2015-06-14 23:53:32 -08:00
// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
// See License.txt for license information.
var utils = require ( '../utils/utils.jsx' ) ;
var client = require ( '../utils/client.jsx' ) ;
var UserStore = require ( '../stores/user_store.jsx' ) ;
SendResetPasswordLink = React . createClass ( {
handleSendLink : function ( e ) {
e . preventDefault ( ) ;
var state = { } ;
var email = this . refs . email . getDOMNode ( ) . value . trim ( ) ;
if ( ! email ) {
state . error = "Please enter a valid email address."
this . setState ( state ) ;
return ;
}
state . error = null ;
this . setState ( state ) ;
data = { } ;
data [ 'email' ] = email ;
2015-07-08 11:50:10 -04:00
data [ 'name' ] = this . props . teamName ;
2015-06-14 23:53:32 -08:00
client . sendPasswordReset ( data ,
2015-07-08 11:50:10 -04:00
function ( data ) {
this . setState ( { error : null , update _text : < p > A password reset link has been sent to < b > { email } < / b > for your < b > { this . props . teamDisplayName } < / b > team on { window . location . hostname } . < / p > , more _update _text : "Please check your inbox." } ) ;
$ ( this . refs . reset _form . getDOMNode ( ) ) . hide ( ) ;
} . bind ( this ) ,
function ( err ) {
this . setState ( { error : err . message , update _text : null , more _update _text : null } ) ;
} . bind ( this )
) ;
2015-06-14 23:53:32 -08:00
} ,
getInitialState : function ( ) {
return { } ;
} ,
render : function ( ) {
var update _text = this . state . update _text ? < div className = "reset-form alert alert-success" > { this . state . update _text } { this . state . more _update _text } < / div > : null ;
var error = this . state . error ? < div className = "form-group has-error" > < label className = "control-label" > { this . state . error } < / label > < / div > : null ;
return (
< div className = "col-sm-12" >
< div className = "signup-team__container" >
< h3 > Password Reset < / h3 >
{ update _text }
< form onSubmit = { this . handleSendLink } ref = "reset_form" >
2015-07-08 11:50:10 -04:00
< p > { "To reset your password, enter the email address you used to sign up for " + this . props . teamDisplayName + "." } < / p >
2015-06-14 23:53:32 -08:00
< div className = { error ? 'form-group has-error' : 'form-group' } >
< input type = "text" className = "form-control" name = "email" ref = "email" placeholder = "Email" / >
< / div >
{ error }
< button type = "submit" className = "btn btn-primary" > Reset my password < / button >
< / form >
< / div >
< / div >
) ;
}
} ) ;
ResetPassword = React . createClass ( {
handlePasswordReset : function ( e ) {
e . preventDefault ( ) ;
var state = { } ;
var password = this . refs . password . getDOMNode ( ) . value . trim ( ) ;
if ( ! password || password . length < 5 ) {
state . error = "Please enter at least 5 characters."
this . setState ( state ) ;
return ;
}
state . error = null ;
this . setState ( state ) ;
data = { } ;
data [ 'new_password' ] = password ;
data [ 'hash' ] = this . props . hash ;
data [ 'data' ] = this . props . data ;
2015-07-08 11:50:10 -04:00
data [ 'name' ] = this . props . teamName ;
2015-06-14 23:53:32 -08:00
client . resetPassword ( data ,
2015-07-08 11:50:10 -04:00
function ( data ) {
this . setState ( { error : null , update _text : "Your password has been updated successfully." } ) ;
} . bind ( this ) ,
function ( err ) {
this . setState ( { error : err . message , update _text : null } ) ;
} . bind ( this )
) ;
2015-06-14 23:53:32 -08:00
} ,
getInitialState : function ( ) {
return { } ;
} ,
render : function ( ) {
2015-07-08 11:50:10 -04:00
var update _text = this . state . update _text ? < div className = "form-group" > < br / > < label className = "control-label reset-form" > { this . state . update _text } Click < a href = { "/" + this . props . teamName + "/login" } > here < / a > to log in . < / label > < / div > : null ;
2015-06-14 23:53:32 -08:00
var error = this . state . error ? < div className = "form-group has-error" > < label className = "control-label" > { this . state . error } < / label > < / div > : null ;
return (
< div className = "col-sm-12" >
< div className = "signup-team__container" >
< h3 > Password Reset < / h3 >
< form onSubmit = { this . handlePasswordReset } >
2015-07-08 11:50:10 -04:00
< p > { "Enter a new password for your " + this . props . teamDisplayName + " " + config . SiteName + " account." } < / p >
2015-06-14 23:53:32 -08:00
< div className = { error ? 'form-group has-error' : 'form-group' } >
< input type = "password" className = "form-control" name = "password" ref = "password" placeholder = "Password" / >
< / div >
{ error }
< button type = "submit" className = "btn btn-primary" > Change my password < / button >
{ update _text }
< / form >
< / div >
< / div >
) ;
}
} ) ;
module . exports = React . createClass ( {
getInitialState : function ( ) {
return { } ;
} ,
render : function ( ) {
if ( this . props . isReset === "false" ) {
return (
< SendResetPasswordLink
2015-07-08 11:50:10 -04:00
teamDisplayName = { this . props . teamDisplayName }
2015-06-14 23:53:32 -08:00
teamName = { this . props . teamName }
/ >
) ;
} else {
return (
< ResetPassword
2015-07-08 11:50:10 -04:00
teamDisplayName = { this . props . teamDisplayName }
2015-06-14 23:53:32 -08:00
teamName = { this . props . teamName }
hash = { this . props . hash }
data = { this . props . data }
/ >
) ;
}
}
} ) ;