|
@@ -54,8 +54,53 @@ class AuthenticationController < ApplicationController
|
54
|
54
|
redirect_to action: 'login'
|
55
|
55
|
end
|
56
|
56
|
|
|
57
|
+ def reset_password_form
|
|
58
|
+ token = Token.find_by(token: params[:token], tokentype: Token::TYPES[:password_reset])
|
|
59
|
+ if not password_reset_token_valid? token
|
|
60
|
+ return
|
|
61
|
+ end
|
|
62
|
+ render layout: 'void'
|
|
63
|
+ end
|
|
64
|
+
|
|
65
|
+ def reset_password
|
|
66
|
+ token = Token.find_by(token: params[:token], tokentype: Token::TYPES[:password_reset])
|
|
67
|
+ if not password_reset_token_valid? token
|
|
68
|
+ return
|
|
69
|
+ end
|
|
70
|
+
|
|
71
|
+ if not params[:password] == params[:password_confirmation]
|
|
72
|
+ flash[:warning] = "Password confirmation does not match your password!"
|
|
73
|
+ redirect_to action: 'reset_password_form', token: params[:token]
|
|
74
|
+ return
|
|
75
|
+ end
|
|
76
|
+
|
|
77
|
+ user = token.user
|
|
78
|
+ user.password = params[:password_reset][:password]
|
|
79
|
+ user.password_confirmation = params[:password_reset][:password_confirmation]
|
|
80
|
+ user.save!
|
|
81
|
+
|
|
82
|
+ token.destroy!
|
|
83
|
+
|
|
84
|
+ flash[:success] = "Your password has been reset, you may now log in."
|
|
85
|
+ redirect_to action: 'login'
|
|
86
|
+ end
|
|
87
|
+
|
57
|
88
|
private
|
58
|
89
|
def session_params
|
59
|
90
|
params.require(:session).permit(:email, :password, :remember_me)
|
60
|
91
|
end
|
|
92
|
+
|
|
93
|
+ def password_reset_token_valid?(token)
|
|
94
|
+ if token.nil?
|
|
95
|
+ flash[:warning] = "No valid token specified!"
|
|
96
|
+ redirect_to action: 'login'
|
|
97
|
+ return false
|
|
98
|
+ end
|
|
99
|
+ if token.expires and token.expires < DateTime.now
|
|
100
|
+ flash[:warning] = "That token has expired, please request a new one."
|
|
101
|
+ redirect_to action: 'login'
|
|
102
|
+ return false
|
|
103
|
+ end
|
|
104
|
+ true
|
|
105
|
+ end
|
61
|
106
|
end
|