This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
lnauth/classes/lnAuth/Controller/Login.php
2014-10-22 22:04:44 +11:00

110 lines
3.1 KiB
PHP

<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides Login capability
*
* @package lnAuth
* @category Controllers
* @author Deon George
* @copyright (c) 2014 Deon George
* @license http://dev.leenooks.net/license.html
*/
abstract class lnAuth_Controller_Login extends lnApp_Controller_Login {
/**
* Activate an account so that it can login and use the site
*/
public function action_activate() {
if ($this->request->post()) {
$ao = ORM::factory('Account',array('id'=>$this->request->param('id'),'email'=>$this->request->post('email')));
if ($ao->loaded()) {
if ($ao->activated())
HTTP::redirect('login');
elseif (! $ao->active) {
SystemMessage::factory()
->title(_('Account NOT Activated'))
->type('warning')
->body(_('Your account cannot been activated, please contact us.'));
} 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();
SystemMessage::factory()
->title(_('Account Activated'))
->type('info')
->body(_('Your account has been activated.'));
}
HTTP::redirect('welcome');
}
} elseif (! $this->request->param('id'))
HTTP::redirect('login/activate_resend');
Block::factory()
->title('Activate account')
->title_icon('fa-wrench')
->type('form-horizontal')
->body(View::factory('login/activate')->set('o',Session::instance()->get_once('activate'))->set('email',$this->request->query('email')));
}
/**
* Register for an account on the site
*/
public function action_register() {
$ao = ORM::factory('Account',$this->request->param('id'));
if ($this->request->post()) {
$ao->values($this->request->post());
$ao->active = "1";
if ($ao->changed() AND (! $this->save($ao)))
$ao->reload()->values($this->request->post());
}
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')
->title('Register Account')
->title_icon('fa-edit')
->body(View::factory('account/user/edit')->set('o',$ao));
}
}
?>