Class: UsersController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- UsersController
- Defined in:
- lib/generators/fetty/authentication/templates/controllers/users_controller.rb
Instance Method Summary collapse
- #activate ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#activate ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/generators/fetty/authentication/templates/controllers/users_controller.rb', line 67 def activate @user = User.activate!(params[:id],params[:token]) if @user.is_a? User (@user) redirect_to root_url, :notice => "Your account has been activated!" elsif @user == UsersAuthentication::Status::Unexist raise "Invalid user account and activation code" elsif @user == UsersAuthentication::Status::Activated raise "You already activated this account." end rescue Exception => e (nil) redirect_to new_session_url, :alert => e. end |
#create ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/generators/fetty/authentication/templates/controllers/users_controller.rb', line 26 def create @user = User.new(:username => params[:username], :email => params[:email], :password => params[:password], :password_confirmation => params[:password_confirmation]) if @user.save @user.send_activation_mail redirect_to new_session_url, :notice => "Activation link has been sent to your email. Please activate first!" else raise "Unable to create user account." end rescue Exception => e flash.now[:alert] = e. render :action => 'new' end |
#destroy ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/generators/fetty/authentication/templates/controllers/users_controller.rb', line 55 def destroy @user = User.find(params[:id]) if current_user === @user (nil) @user.destroy redirect_to new_session_url, :notice => "Your account has been deleted." else @user.destroy redirect_to users_url, :notice => "account has been deleted." end end |
#edit ⇒ Object
39 40 41 |
# File 'lib/generators/fetty/authentication/templates/controllers/users_controller.rb', line 39 def edit @user = User.find(params[:id]) end |
#index ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/generators/fetty/authentication/templates/controllers/users_controller.rb', line 4 def index @users = User.all respond_to do |format| format.html # index.html.erb format.xml { render :xml => @users } format.js end end |
#new ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/generators/fetty/authentication/templates/controllers/users_controller.rb', line 18 def new unless user_signed_in? @user = User.new else redirect_to redirect_to_target_or_default_url, :alert => "You already sign-up! Please log-out first." end end |
#show ⇒ Object
14 15 16 |
# File 'lib/generators/fetty/authentication/templates/controllers/users_controller.rb', line 14 def show @user = User.find(params[:id]) end |
#update ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/generators/fetty/authentication/templates/controllers/users_controller.rb', line 43 def update @user = User.find(params[:id]) if @user.update_attributes(:username => params[:username], :email => params[:email], :password => params[:password], :password_confirmation => params[:password_confirmation]) redirect_to user_path(@user), :notice => "Your profile has been updated." else raise "Unable to update your profile." end rescue Exception => e flash.now[:alert] = e. render :action => 'edit' end |