Login/Activation tested
This commit is contained in:
@@ -25,21 +25,15 @@ class lnApp_Controller_Login extends Controller_TemplateDefault {
|
||||
HTTP::redirect('login');
|
||||
|
||||
elseif ($ao->activate_code() == $this->request->post('code')) {
|
||||
$go = ORM::factory('Group',array('name'=>'Registered Users'));
|
||||
|
||||
$ago = ORM::factory('Account_Group',array('account_id'=>$ao,'group_id'=>$go));
|
||||
|
||||
if (! $ago->loaded()) {
|
||||
$ago->account_id=$ao;
|
||||
$ago->group_id=$go;
|
||||
}
|
||||
$ago->active = TRUE;
|
||||
$ago->save();
|
||||
$ao->verified = TRUE;
|
||||
$ao->save();
|
||||
|
||||
SystemMessage::factory()
|
||||
->title(_('Account Activated'))
|
||||
->type('info')
|
||||
->body(_('Your account has been activated.'));
|
||||
|
||||
HTTP::redirect('welcome');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,6 +76,7 @@ class lnApp_Controller_Login extends Controller_TemplateDefault {
|
||||
|
||||
// Log the password reset
|
||||
$ao->log('Activation code sent');
|
||||
|
||||
Session::instance()->set('activate',$ao);
|
||||
}
|
||||
}
|
||||
@@ -167,10 +162,33 @@ class lnApp_Controller_Login extends Controller_TemplateDefault {
|
||||
$ao = ORM::factory('Account',$this->request->param('id'));
|
||||
|
||||
if ($this->request->post() AND $ao->values($this->request->post())->changed() AND (! $this->save($ao)))
|
||||
$ao->reload()->values($this->request->post());
|
||||
$ao->reload()->values($this->request->post());
|
||||
|
||||
if ($ao->loaded())
|
||||
HTTP::redirect('login');
|
||||
if ($ao->loaded()) {
|
||||
$co = Company::instance();
|
||||
|
||||
// Send our email with the token
|
||||
$email = Email::factory('login_activate')
|
||||
->set('SITE',URL::base(TRUE,TRUE))
|
||||
->set('SITE_ADMIN',$co->admin()->name())
|
||||
->set('CODE',$ao->activate_code())
|
||||
->set('EMAIL',$ao->email)
|
||||
->set('ID',$ao->id)
|
||||
->set('USER_NAME',$ao->name());
|
||||
|
||||
$email->to = array('email'=>array($ao->email=>$ao->name()));
|
||||
$email->from = array('email'=>array($co->admin()->email=>$co->admin()->name()));
|
||||
$email->subject = 'Please activate your account for '.$co->name();
|
||||
$email->deliver();
|
||||
|
||||
SystemMessage::factory()
|
||||
->title(_('Account Registered'))
|
||||
->type('info')
|
||||
->body(_('Please check your email for more instructions!'));
|
||||
|
||||
Session::instance()->set('activate',$ao);
|
||||
HTTP::redirect('login/activate/'.$ao->id);
|
||||
}
|
||||
|
||||
Block::factory()
|
||||
->type('form-horizontal')
|
||||
@@ -184,33 +202,26 @@ class lnApp_Controller_Login extends Controller_TemplateDefault {
|
||||
*/
|
||||
public function action_reset() {
|
||||
// Minutes to keep our token
|
||||
$token_expire = 15;
|
||||
$co = Company::instance();
|
||||
|
||||
// If user already signed-in
|
||||
if (Auth::instance()->logged_in())
|
||||
HTTP::redirect('welcome/index');
|
||||
$token_expire = 15*60;
|
||||
|
||||
// If the user posted their details to reset their password
|
||||
if ($this->request->post()) {
|
||||
// If the username is correct, create a method token
|
||||
if ($ao=ORM::factory('Account',array('email'=>$this->request->post('username'))) AND $ao->loaded()) {
|
||||
$mmto = ORM::factory('Module_Method_Token')
|
||||
->method(array('account','user:resetpassword'))
|
||||
->account($ao)
|
||||
->uses(2)
|
||||
->expire(time()+$token_expire*60);
|
||||
$token = $ao->token($token_expire,'account','user:resetpassword',2);
|
||||
|
||||
if ($token) {
|
||||
$co = Company::instance();
|
||||
|
||||
if ($mmto->generate()) {
|
||||
// Send our email with the token
|
||||
$email = Email::factory('login_reset')
|
||||
->set('SITE',URL::base(TRUE,TRUE))
|
||||
->set('SITE_ADMIN',$co->admin()->name())
|
||||
->set('TOKEN',$mmto->token)
|
||||
->set('TOKEN',$token)
|
||||
->set('TOKEN_EXPIRE_MIN',$token_expire)
|
||||
->set('USER_NAME',$mmto->account->name());
|
||||
->set('USER_NAME',$ao->name());
|
||||
|
||||
$email->to = array('email'=>array($mmto->account->email=>$mmto->account->name()));
|
||||
$email->to = array('email'=>array($ao->email=>$ao->name()));
|
||||
$email->from = array('email'=>array($co->admin()->email=>$co->admin()->name()));
|
||||
$email->subject = 'Login Reset Token for '.$co->name();
|
||||
$email->deliver();
|
||||
|
Reference in New Issue
Block a user