Ejemplo n.º 1
0
 /**
  * Activate your account with token
  */
 public function activate()
 {
     $this->_rejectLogged();
     $token = $this->request->params['token'];
     $id = $this->request->params['id'];
     $user = null;
     $activation = null;
     if ($token && $id) {
         UserActivations::activate(array('user_id' => $id, 'token' => $token));
     }
     return $this->redirect('li3_usermanager.Session::create');
 }
 /**
  * Activate user
  */
 public function backend_activate()
 {
     $success = false;
     $user = null;
     if ($id = $this->request->params['id']) {
         $user = Users::first(array('conditions' => compact('id')));
         if ($user && !$user->active) {
             $user->active = 1;
             $success = $user->save();
             if ($success) {
                 $activation = UserActivations::first(array('conditions' => array('user_id' => $id)));
                 if ($activation) {
                     $activation->delete();
                 }
             }
         }
     }
     return compact('success', 'user');
 }
Ejemplo n.º 3
0
 /**
  * Apply proper password hashing (on create or change password)
  * On create:
  * 	- apply defined default user group (LI3_UM_DefaultUserGroup)
  * 	- apply defined active status (LI3_UM_RequireUserActivation)
  * 	  0 - require user to activate account trough generated link with token
  *    1 - don't require further actions, account is already activated
  */
 public static function __init()
 {
     static::applyFilter('save', function ($self, $params, $chain) {
         if ($params['data']) {
             $params['entity']->set($params['data']);
             $params['data'] = array();
         }
         if (!$params['entity']->exists()) {
             if ($params['entity']->password) {
                 $params['entity']->password = Password::hash($params['entity']->password);
             }
             $params['entity']->active = 1;
             if (LI3_UM_RequireUserActivation && $self::$request) {
                 $params['entity']->active = 0;
             }
             $params['entity']->user_group_id = LI3_UM_DefaultUserGroup;
         } else {
             if ($params['entity']->password && $params['entity']->modified('password')) {
                 $params['entity']->password = Password::hash($params['entity']->password);
             }
         }
         return $chain->next($self, $params, $chain);
     });
     static::applyFilter('save', function ($self, $params, $chain) {
         if (($save = $chain->next($self, $params, $chain)) && $params['options']['events'] === 'create') {
             $user = $params['entity'];
             AboutUsers::create(array('user_id' => $user->id))->save();
             if (LI3_UM_RequireUserActivation && $self::$request) {
                 $token = Token::generate($user->email);
                 UserActivations::create(array('user_id' => $user->id, 'token' => $token))->save();
                 $link = Router::match(array('li3_usermanager.Users::activate', 'id' => $user->id, 'token' => $token), $self::$request, array('absolute' => true));
                 Mailer::$_data['subject'] = 'Your activation link!';
                 Mailer::$_data['from'] = LI3_UM_ActivationEmailFrom;
                 Mailer::$_data['to'] = $user->email;
                 Mailer::$_data['body'] = 'This is your activation link:' . "\n" . $link;
             }
         }
         return $save;
     });
 }