+ @user.display_name = params[:user][:display_name]
+
+ if params[:user][:pass_crypt].length > 0 or params[:user][:pass_crypt_confirmation].length > 0
+ @user.pass_crypt = params[:user][:pass_crypt]
+ @user.pass_crypt_confirmation = params[:user][:pass_crypt_confirmation]
+ end
+
+ @user.description = params[:user][:description]
+ @user.languages = params[:user][:languages].split(",")
+ @user.home_lat = params[:user][:home_lat]
+ @user.home_lon = params[:user][:home_lon]
+
+ if @user.save
+ set_locale
+
+ if params[:user][:email] == @user.new_email
+ flash[:notice] = I18n.t('user.account.flash update success confirm needed')
+ Notifier.deliver_email_confirm(@user, @user.tokens.create)
+ else
+ flash[:notice] = I18n.t('user.account.flash update success')
+ end
+ end
+ end
+ end
+
+ def set_home
+ if params[:user][:home_lat] and params[:user][:home_lon]
+ @user.home_lat = params[:user][:home_lat].to_f
+ @user.home_lon = params[:user][:home_lon].to_f
+ if @user.save
+ flash[:notice] = I18n.t('user.set_home.flash success')
+ redirect_to :controller => 'user', :action => 'account'
+ end
+ end
+ end
+
+ def go_public
+ @user.data_public = true
+ @user.save
+ flash[:notice] = I18n.t('user.go_public.flash success')
+ redirect_to :controller => 'user', :action => 'account', :display_name => @user.display_name
+ end
+
+ def lost_password
+ @title = I18n.t('user.lost_password.title')
+ if params[:user] and params[:user][:email]
+ user = User.find_by_email(params[:user][:email], :conditions => {:visible => true})
+
+ if user
+ token = user.tokens.create
+ Notifier.deliver_lost_password(user, token)
+ flash[:notice] = I18n.t('user.lost_password.notice.email on way')
+ else
+ flash[:notice] = I18n.t('user.lost_password.notice email cannot find')
+ end
+ end
+ end
+
+ def reset_password
+ @title = I18n.t('user.reset_password.title')
+ if params['token']
+ token = UserToken.find_by_token(params[:token])
+ if token
+ pass = OSM::make_token(8)
+ user = token.user
+ user.pass_crypt = pass
+ user.pass_crypt_confirmation = pass
+ user.active = true
+ user.email_valid = true
+ user.save!
+ token.destroy
+ Notifier.deliver_reset_password(user, pass)
+ flash[:notice] = I18n.t('user.reset_password.flash changed check mail')
+ else
+ flash[:notice] = I18n.t('user.reset_password.flash token bad')
+ end
+ end
+
+ redirect_to :action => 'login'