Added auto login after password reset.
This commit is contained in:
parent
03053e7727
commit
ffa6259099
4 changed files with 44 additions and 16 deletions
|
@ -113,6 +113,7 @@ class Verify extends App.Controller
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
params = @formParam(e.target)
|
params = @formParam(e.target)
|
||||||
params['token'] = @token
|
params['token'] = @token
|
||||||
|
@password = params['password']
|
||||||
|
|
||||||
# get data
|
# get data
|
||||||
App.Com.ajax(
|
App.Com.ajax(
|
||||||
|
@ -126,6 +127,35 @@ class Verify extends App.Controller
|
||||||
)
|
)
|
||||||
|
|
||||||
render_changed_success: (data, status, xhr) =>
|
render_changed_success: (data, status, xhr) =>
|
||||||
|
App.Auth.login(
|
||||||
|
data:
|
||||||
|
username: data.user_login
|
||||||
|
password: @password
|
||||||
|
success: =>
|
||||||
|
|
||||||
|
# login check
|
||||||
|
App.Auth.loginCheck()
|
||||||
|
|
||||||
|
# add notify
|
||||||
|
App.Event.trigger 'notify:removeall'
|
||||||
|
@notify
|
||||||
|
type: 'success',
|
||||||
|
msg: 'Password reset successfull.'
|
||||||
|
|
||||||
|
# redirect to #
|
||||||
|
@navigate '#'
|
||||||
|
|
||||||
|
error: =>
|
||||||
|
|
||||||
|
# add notify
|
||||||
|
App.Event.trigger 'notify:removeall'
|
||||||
|
@notify
|
||||||
|
type: 'error',
|
||||||
|
msg: 'Something went wrong. Please contact your administrator.'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@html App.view('generic/hero_message')(
|
@html App.view('generic/hero_message')(
|
||||||
head: 'Woo hoo! Your password has been changed!'
|
head: 'Woo hoo! Your password has been changed!'
|
||||||
message: 'Please try to login!'
|
message: 'Please try to login!'
|
||||||
|
|
|
@ -341,12 +341,12 @@ curl http://localhost/api/users/password_reset_verify.json -v -u #{login}:#{pass
|
||||||
|
|
||||||
def password_reset_verify
|
def password_reset_verify
|
||||||
if params[:password]
|
if params[:password]
|
||||||
success = User.password_reset_via_token( params[:token], params[:password] )
|
user = User.password_reset_via_token( params[:token], params[:password] )
|
||||||
else
|
else
|
||||||
success = User.password_reset_check( params[:token] )
|
user = User.password_reset_check( params[:token] )
|
||||||
end
|
end
|
||||||
if success
|
if user
|
||||||
render :json => { :message => 'ok' }, :status => :ok
|
render :json => { :message => 'ok', :user_login => user.login }, :status => :ok
|
||||||
else
|
else
|
||||||
render :json => { :message => 'failed' }, :status => :unprocessable_entity
|
render :json => { :message => 'failed' }, :status => :unprocessable_entity
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,7 +19,7 @@ class Token < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
# return token if valid
|
# return token if valid
|
||||||
return token
|
return token.user
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -145,24 +145,22 @@ Your #{config.product_name} Team
|
||||||
|
|
||||||
# check token
|
# check token
|
||||||
def self.password_reset_check(token)
|
def self.password_reset_check(token)
|
||||||
token = Token.check( :action => 'PasswordReset', :name => token )
|
user = Token.check( :action => 'PasswordReset', :name => token )
|
||||||
return if !token
|
return user
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.password_reset_via_token(token,password)
|
def self.password_reset_via_token(token,password)
|
||||||
|
|
||||||
# check token
|
# check token
|
||||||
token = Token.check( :action => 'PasswordReset', :name => token )
|
user = Token.check( :action => 'PasswordReset', :name => token )
|
||||||
return if !token
|
return if !user
|
||||||
|
|
||||||
# reset password
|
# reset password
|
||||||
token.user.update_attributes( :password => password )
|
user.update_attributes( :password => password )
|
||||||
|
|
||||||
# delete token
|
# delete token
|
||||||
token.delete
|
Token.where( :action => 'PasswordReset', :name => token ).first.destroy
|
||||||
token.save
|
return user
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.find_fulldata(user_id)
|
def self.find_fulldata(user_id)
|
||||||
|
|
Loading…
Reference in a new issue