Class: Identities

Inherits:
UserManagement show all
Defined in:
app/controllers/identities.rb

Instance Method Summary collapse

Instance Method Details

#enter_emailObject



34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/identities.rb', line 34

def enter_email
  @token = Models::User::EmailVerificationToken.new params.token
  @token.expires_at = 2.weeks.from_now
  if @token.save
    UserMailer.email_verification(@token).deliver
    flash.sticky_info = t :email_verification_code_sent, email: @token.email
    redirect_to :follow_email_link
  else
    render action: :enter_email_form
  end
end

#enter_email_formObject

Email and Password



29
30
31
# File 'app/controllers/identities.rb', line 29

def enter_email_form
  @token = Models::User::EmailVerificationToken.new
end

#finish_email_registrationObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/controllers/identities.rb', line 58

def finish_email_registration
  @token = Models::User::EmailVerificationToken.by_token params.token

  @user = Models::User.new
  @user.email = @token.email
  %w{name password password_confirmation}.each do |a|
    @user.send "#{a}=", params.user[a] if params.user?
  end

  if @user.activate and @user.save
    @token.destroy
    flash.sticky_info = t :successfully_registered
    redirect_to  #(_return_to: nil)
  else
    render action: :finish_email_registration_form
  end
end

#finish_email_registration_formObject



50
51
52
53
54
55
# File 'app/controllers/identities.rb', line 50

def finish_email_registration_form
  @token = Models::User::EmailVerificationToken.by_token params.token
  raise_user_error t(:invalid_email_verification_token) unless @token

  @user = Models::User.new
end

#finish_open_id_registrationObject



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'app/controllers/identities.rb', line 145

def finish_open_id_registration
  @token = Models::SecureToken.by_token! params.token
  @user = Models::User.new
  @user.name = params.user['name']
  @user.open_ids << @token[:open_id]

  if @user.activate and @user.save
    @token.destroy
    flash.sticky_info = t :successfull_open_id_registration
    set_current_user_with_updating_session @user
    redirect_to 
  else
    render action: :finish_open_id_registration_form
  end
end

#finish_open_id_registration_formObject

Open Id



139
140
141
142
# File 'app/controllers/identities.rb', line 139

def finish_open_id_registration_form
  @user = Models::User.new
  @token = Models::SecureToken.by_token! params.token
end


46
47
# File 'app/controllers/identities.rb', line 46

def follow_email_link
end

#forgot_passwordObject



80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/controllers/identities.rb', line 80

def forgot_password
  @email = params.email
  user = Models::User.first state: 'active', email: @email
  if user
    token = Models::User::ForgotPasswordToken.create! user: user
    UserMailer.forgot_password(token).deliver
    flash.sticky_info = t :sucessfully_reset_password, email: @email
    redirect_to default_path
  else
    flash.sticky_error = t :failed_reset_password, email: @email
    render action: :forgot_password_form
  end
end

#forgot_password_formObject



76
77
# File 'app/controllers/identities.rb', line 76

def forgot_password_form
end

#reset_passwordObject



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'app/controllers/identities.rb', line 101

def reset_password
  @token = Models::User::ForgotPasswordToken.by_token params.token
  raise_user_error t(:invalid_reset_password_token) unless @token
  @user = @token.user

  @user.password = params.user['password']
  @user.password_confirmation = params.user['password_confirmation']

  if @user.save
    @token.destroy
    flash.sticky_info = t :password_restored
    redirect_to (_return_to: nil)
  else
    render action: :reset_password_form
  end
end

#reset_password_formObject



94
95
96
97
98
# File 'app/controllers/identities.rb', line 94

def reset_password_form
  @token = Models::User::ForgotPasswordToken.by_token params.token
  raise_user_error t(:invalid_reset_password_token) unless @token
  @user = @token.user
end

#update_passwordObject



124
125
126
127
128
129
130
131
132
133
# File 'app/controllers/identities.rb', line 124

def update_password
  @user = Models::User.current

  if @user.update_password(params.user['password'], params.user['password_confirmation'], params.old_password) and @user.save
    flash.sticky_info = t :password_updated
    redirect_to default_path
  else
    render action: :update_password_form
  end
end

#update_password_formObject



118
119
120
121
# File 'app/controllers/identities.rb', line 118

def update_password_form
  @user = Models::User.current
  # render action: :update_password_form
end