Module: Appoxy::Sessions::UsersController

Defined in:
lib/sessions/users_controller.rb

Instance Method Summary collapse

Instance Method Details

#activateObject

Usually a user gets here via an activation link in email.



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/sessions/users_controller.rb', line 98

def activate
    logout_keeping_session!
    @user = ::User.find_by_activation_code(params[:ac]) unless params[:ac].blank?
    case
        when (!params[:ac].blank?) && @user && !@user.is_active?
            flash[:info] = "Account activated. please login."
            @user.activate!
            redirect_to 
        when params[:ac].blank?
            flash[:error] = "The activation code was missing.  Please follow the URL from your email."
            redirect_to(root_url)
        else
            flash[:error] = "We couldn't find a user with that activation code -- check your email? Or maybe you've already activated -- try signing in."
            redirect_to(root_url)
    end
end

#after_createObject



92
93
94
# File 'lib/sessions/users_controller.rb', line 92

def after_create

end

#after_newObject



23
24
25
# File 'lib/sessions/users_controller.rb', line 23

def after_new

end

#after_save_in_createObject



88
89
90
# File 'lib/sessions/users_controller.rb', line 88

def after_save_in_create

end

#before_createObject



80
81
82
# File 'lib/sessions/users_controller.rb', line 80

def before_create

end

#before_newObject



19
20
21
# File 'lib/sessions/users_controller.rb', line 19

def before_new

end

#before_save_in_createObject



84
85
86
# File 'lib/sessions/users_controller.rb', line 84

def before_save_in_create

end

#createObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/sessions/users_controller.rb', line 27

def create

    before_create

    @user = ::User.new(params[:user])

    if @user.password != params[:password_confirmation]
        flash[:error] = "Confirmation password does not match. Please try again."
        render :action=>"new"
        return
    end

    if params[:user][:password].length < 6
        flash[:error] = "Password can not be less than 6 characters."
        render :action=>"new"
        return
    end

    existing_user = ::User.find_by_email(@user.email)

    if existing_user
        if params[:ac]
            
        end
        # todo: remove activation_code on user
        if @user.activation_code.present?
            # hasn't logged in yet, probably invited, need to check access key
            if existing_user.activation_code == @user.activation_code
                existing_user.activate!
                existing_user.password = @user.password
                @user = existing_user
            end
        else
            flash[:error] = "The email you entered already exists in our system. You might want to try logging in if you already have an account."
            render :action=>"new"
            return
        end
    else
        @user.status = "active"
    end

    before_save_in_create
    if @user.save
        self.current_user = @user
        flash[:success] = "Your account was created successfully."
        after_save_in_create
        after_create
    else
        render :action => "new"
    end

end

#newObject



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/sessions/users_controller.rb', line 7

def new
    before_new
    if params[:id]
        @user = ::User.find params[:id]
    else
        @user = ::User.new
        @user.email = params[:email] if params[:email]
    end
    @user.activation_code = params[:ac] if params[:ac]
    after_new
end