+ if @user.save
+ flash[:notice] = t 'user.new.flash create success message'
+ Notifier.deliver_signup_confirm(@user, @user.tokens.create(:referer => params[:referer]))
+ redirect_to :action => 'login'
+ else
+ render :action => 'new'
+ end
+ end
+ end
+
+ def account
+ @title = t 'user.account.title'
+ @tokens = @user.oauth_tokens.find :all, :conditions => 'oauth_tokens.invalidated_at is null and oauth_tokens.authorized_at is not null'
+
+ if params[:user] and params[:user][:display_name] and params[:user][:description]
+ @user.display_name = params[:user][:display_name]
+ @user.new_email = params[:user][:new_email]
+
+ 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(",")
+
+ case params[:image_action]
+ when "new" then @user.image = params[:user][:image]
+ when "delete" then @user.image = nil
+ end
+
+ @user.home_lat = params[:user][:home_lat]
+ @user.home_lon = params[:user][:home_lon]
+
+ if @user.save
+ set_locale
+
+ if @user.new_email.nil? or @user.new_email.empty?
+ flash[:notice] = t 'user.account.flash update success'
+ else
+ flash[:notice] = t 'user.account.flash update success confirm needed'
+
+ begin
+ Notifier.deliver_email_confirm(@user, @user.tokens.create)
+ rescue
+ # Ignore errors sending email
+ end
+ end
+
+ redirect_to :action => "account", :display_name => @user.display_name
+ end
+ else
+ if flash[:errors]
+ flash[:errors].each do |attr,msg|
+ attr = "new_email" if attr == "email"
+ @user.errors.add(attr,msg)
+ end
+ end
+ end
+ end
+
+ def go_public
+ @user.data_public = true
+ @user.save
+ flash[:notice] = t 'user.go_public.flash success'
+ redirect_to :controller => 'user', :action => 'account', :display_name => @user.display_name
+ end
+
+ def lost_password
+ @title = t 'user.lost_password.title'
+
+ if params[:user] and params[:user][:email]
+ user = User.find_by_email(params[:user][:email], :conditions => {:status => ["pending", "active", "confirmed"]})
+
+ if user
+ token = user.tokens.create
+ Notifier.deliver_lost_password(user, token)
+ flash[:notice] = t 'user.lost_password.notice email on way'
+ redirect_to :action => 'login'
+ else
+ flash.now[:error] = t 'user.lost_password.notice email cannot find'
+ end
+ end
+ end
+
+ def reset_password
+ @title = t 'user.reset_password.title'
+
+ if params[:token]
+ token = UserToken.find_by_token(params[:token])
+
+ if token
+ @user = token.user
+
+ if params[:user]
+ @user.pass_crypt = params[:user][:pass_crypt]
+ @user.pass_crypt_confirmation = params[:user][:pass_crypt_confirmation]
+ @user.status = "active" if @user.status == "pending"
+ @user.email_valid = true
+
+ if @user.save
+ token.destroy
+ flash[:notice] = t 'user.reset_password.flash changed'
+ redirect_to :action => 'login'
+ end
+ end
+ else
+ flash[:error] = t 'user.reset_password.flash token bad'
+ redirect_to :action => 'lost_password'
+ end
+ end