Improved password reset feature.
This commit is contained in:
parent
ce6356c6f8
commit
fae9b57df3
5 changed files with 101 additions and 26 deletions
|
@ -6,7 +6,6 @@ class Index extends App.Controller
|
||||||
events:
|
events:
|
||||||
'submit form': 'submit',
|
'submit form': 'submit',
|
||||||
'click .submit': 'submit',
|
'click .submit': 'submit',
|
||||||
'click .cancel': 'cancel',
|
|
||||||
|
|
||||||
constructor: ->
|
constructor: ->
|
||||||
super
|
super
|
||||||
|
@ -18,7 +17,6 @@ class Index extends App.Controller
|
||||||
@render()
|
@render()
|
||||||
|
|
||||||
render: ->
|
render: ->
|
||||||
|
|
||||||
configure_attributes = [
|
configure_attributes = [
|
||||||
{ name: 'username', display: 'Enter your username or email address:', tag: 'input', type: 'text', limit: 100, null: false, class: 'input span4', },
|
{ name: 'username', display: 'Enter your username or email address:', tag: 'input', type: 'text', limit: 100, null: false, class: 'input span4', },
|
||||||
]
|
]
|
||||||
|
@ -27,11 +25,7 @@ class Index extends App.Controller
|
||||||
form: @formGen( model: { configure_attributes: configure_attributes } ),
|
form: @formGen( model: { configure_attributes: configure_attributes } ),
|
||||||
)
|
)
|
||||||
|
|
||||||
cancel: ->
|
|
||||||
@navigate 'login'
|
|
||||||
|
|
||||||
submit: (e) ->
|
submit: (e) ->
|
||||||
@log 'submit'
|
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
params = @formParam(e.target)
|
params = @formParam(e.target)
|
||||||
|
|
||||||
|
@ -46,22 +40,82 @@ class Index extends App.Controller
|
||||||
)
|
)
|
||||||
|
|
||||||
success: (data, status, xhr) =>
|
success: (data, status, xhr) =>
|
||||||
|
@html App.view('generic/hero_message')(
|
||||||
@html App.view('reset_password_sent')()
|
head: 'We\'ve sent password reset instructions to your email address',
|
||||||
|
message: 'If you don\'t receive instructions within a minute or two, check your email\'s spam and junk filters, or try <a href="#reset_password">resending your request</a>.'
|
||||||
error: (xhr, statusText, error) =>
|
);
|
||||||
|
|
||||||
# add notify
|
|
||||||
Spine.trigger 'notify:removeall'
|
|
||||||
Spine.trigger 'notify', {
|
|
||||||
type: 'warning',
|
|
||||||
msg: 'Wrong Username and Password combination.',
|
|
||||||
}
|
|
||||||
|
|
||||||
# rerender login page
|
|
||||||
@render(
|
|
||||||
msg: 'Wrong Username and Password combination.',
|
|
||||||
username: @username
|
|
||||||
)
|
|
||||||
|
|
||||||
Config.Routes['reset_password'] = Index
|
Config.Routes['reset_password'] = Index
|
||||||
|
|
||||||
|
|
||||||
|
class Verify extends App.Controller
|
||||||
|
className: 'container'
|
||||||
|
|
||||||
|
events:
|
||||||
|
'submit form': 'submit',
|
||||||
|
'click .submit': 'submit',
|
||||||
|
|
||||||
|
constructor: ->
|
||||||
|
super
|
||||||
|
|
||||||
|
# set title
|
||||||
|
@title 'Reset Password'
|
||||||
|
@navupdate '#reset_password_verify'
|
||||||
|
|
||||||
|
# get data
|
||||||
|
ajax = new App.Ajax
|
||||||
|
params = {}
|
||||||
|
params['token'] = @token
|
||||||
|
ajax.ajax(
|
||||||
|
type: 'POST',
|
||||||
|
url: '/users/password_reset_verify',
|
||||||
|
data: JSON.stringify(params),
|
||||||
|
processData: true,
|
||||||
|
success: @render_success
|
||||||
|
error: @render_failed
|
||||||
|
)
|
||||||
|
|
||||||
|
render_success: ->
|
||||||
|
configure_attributes = [
|
||||||
|
{ name: 'password', display: 'Password', tag: 'input', type: 'password', limit: 100, null: false, class: 'input span4', },
|
||||||
|
]
|
||||||
|
|
||||||
|
@html App.view('reset_password_change')(
|
||||||
|
form: @formGen( model: { configure_attributes: configure_attributes } ),
|
||||||
|
)
|
||||||
|
|
||||||
|
render_failed: ->
|
||||||
|
@html App.view('generic/hero_message')(
|
||||||
|
head: 'Failed!',
|
||||||
|
message: 'Token is not valid!'
|
||||||
|
);
|
||||||
|
|
||||||
|
submit: (e) ->
|
||||||
|
e.preventDefault()
|
||||||
|
params = @formParam(e.target)
|
||||||
|
params['token'] = @token
|
||||||
|
|
||||||
|
# get data
|
||||||
|
ajax = new App.Ajax
|
||||||
|
ajax.ajax(
|
||||||
|
type: 'POST',
|
||||||
|
url: '/users/password_reset_verify',
|
||||||
|
data: JSON.stringify(params),
|
||||||
|
processData: true,
|
||||||
|
success: @render_changed_success
|
||||||
|
error: @render_changed_failed
|
||||||
|
)
|
||||||
|
|
||||||
|
render_changed_success: (data, status, xhr) =>
|
||||||
|
@html App.view('generic/hero_message')(
|
||||||
|
head: 'Woo hoo! Your password has been changed!',
|
||||||
|
message: 'Please try to login!',
|
||||||
|
);
|
||||||
|
|
||||||
|
render_changed_failed: ->
|
||||||
|
@html App.view('generic/hero_message')(
|
||||||
|
head: 'Failed!',
|
||||||
|
message: 'Ask your admin!',
|
||||||
|
);
|
||||||
|
|
||||||
|
Config.Routes['reset_password_verify/:token'] = Verify
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
<div class="hero-unit">
|
||||||
|
<h2><%= @head %> <small><%= @head_small %></small></h2>
|
||||||
|
<div class="container">
|
||||||
|
<p>
|
||||||
|
<%- @message %>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
|
@ -0,0 +1,11 @@
|
||||||
|
<div class="hero-unit">
|
||||||
|
<h2>Choose your new password.<small></small></h2>
|
||||||
|
<div class="container">
|
||||||
|
<form>
|
||||||
|
<p>
|
||||||
|
<%- @form %>
|
||||||
|
</p>
|
||||||
|
<button class="btn btn-primary submit">Submit</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
|
@ -101,7 +101,6 @@ class UsersController < ApplicationController
|
||||||
|
|
||||||
# POST /users/reset_password
|
# POST /users/reset_password
|
||||||
def password_reset_send
|
def password_reset_send
|
||||||
puts params.inspect
|
|
||||||
success = User.password_reset_send( params[:username] )
|
success = User.password_reset_send( params[:username] )
|
||||||
if success
|
if success
|
||||||
render :json => { :message => 'ok' }, :status => :ok
|
render :json => { :message => 'ok' }, :status => :ok
|
||||||
|
@ -112,7 +111,11 @@ class UsersController < ApplicationController
|
||||||
|
|
||||||
# get /users/verify_password/:hash
|
# get /users/verify_password/:hash
|
||||||
def password_reset_verify
|
def password_reset_verify
|
||||||
success = User.password_reset_verify( params[:hash] )
|
if params[:password]
|
||||||
|
success = User.password_reset_via_token( params[:token], params[:password] )
|
||||||
|
else
|
||||||
|
success = User.password_reset_check( params[:token] )
|
||||||
|
end
|
||||||
if success
|
if success
|
||||||
render :json => { :message => 'ok' }, :status => :ok
|
render :json => { :message => 'ok' }, :status => :ok
|
||||||
else
|
else
|
||||||
|
|
|
@ -63,7 +63,6 @@ class User < ApplicationModel
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.password_reset_send(username)
|
def self.password_reset_send(username)
|
||||||
puts '2'+username.inspect
|
|
||||||
return if !username || username == ''
|
return if !username || username == ''
|
||||||
|
|
||||||
# try to find user based on login
|
# try to find user based on login
|
||||||
|
|
Loading…
Reference in a new issue