Class: UsersController

Inherits:
ApplicationController
  • Object
show all
Defined in:
lib/generators/fetty/authentication/templates/controllers/users_controller.rb

Instance Method Summary collapse

Instance Method Details

#activateObject



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
    set_session_or_cookies(@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
  set_session_or_cookies(nil)
  redirect_to new_session_url, :alert => e.message
end

#createObject



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.message
  render :action => 'new'
end

#destroyObject



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
    set_session_or_cookies(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

#editObject



39
40
41
# File 'lib/generators/fetty/authentication/templates/controllers/users_controller.rb', line 39

def edit
  @user = User.find(params[:id])
end

#indexObject



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

#newObject



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

#showObject



14
15
16
# File 'lib/generators/fetty/authentication/templates/controllers/users_controller.rb', line 14

def show
  @user = User.find(params[:id])
end

#updateObject



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.message
  render :action => 'edit'
end