Added auto login after password reset.

This commit is contained in:
Martin Edenhofer 2013-01-03 13:00:55 +01:00
parent 03053e7727
commit ffa6259099
4 changed files with 44 additions and 16 deletions

View file

@ -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!'

View file

@ -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

View file

@ -11,15 +11,15 @@ class Token < ActiveRecord::Base
# check if token is still valid # check if token is still valid
if token.created_at < 1.day.ago if token.created_at < 1.day.ago
# delete token # delete token
token.delete token.delete
token.save token.save
return return
end end
# return token if valid # return token if valid
return token return token.user
end end
private private

View file

@ -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)