Ejemplo n.º 1
0
 public function postSignUp()
 {
     $data = \Data::post()->all();
     $UserDataModel = new \App\data_model\User($data);
     if (!$UserDataModel->verify()) {
         \Session::setFlash('signup-data', $UserDataModel->getData());
         \Session::setFlash('signup-errors', $UserDataModel->getErrors());
     } else {
         $UserRecord = new \App\record\User($data);
         $UserRecord['password'] = \Crypt::hash($UserRecord['password']);
         $UserRecord['created_on_date'] = array('raw' => 'NOW()');
         $UserRecord->insert();
         \App::with('User')->sendActivationEmail($UserRecord['id']);
         \Session::setFlash('signup-success', 1);
     }
     //el
     \View::redirect('/signup');
 }
Ejemplo n.º 2
0
 /**
  * Generate a token to be used for email security that is unique for a user.
  *
  *
  * @param int $user_id The user id.
  * @param string $token_type The token type.
  * @param null|int $expires_days `null` if the token doesn't expire, otherwise a integer representing the 
  * number of days the token will be valid for. Default is `5` days.
  *
  * @return string
  */
 public function generateToken($user_id, $token_type, $expires_days = 5)
 {
     $User = new \App\record\User(array('id' => $user_id));
     if (!$User->exists()) {
         return false;
     }
     //if
     $user_has_token = \App\record\UserToken::find(array('user_id' => $User->id, 'type' => $token_type), 'id');
     $Token = new \App\record\UserToken();
     $Token->user_id = $User->id;
     $Token->token = str_replace('/', '|', base64_encode(openssl_random_pseudo_bytes(128)));
     $Token->created_on_date = array('raw' => 'NOW()');
     if (is_int($expires_days)) {
         $Token->expires_on_date = array('raw' => '(NOW() + INTERVAL ' . $expires_days . ' DAY)');
     }
     //if
     $Token->type = $token_type;
     if ($user_has_token === false) {
         $Token->insert();
     } else {
         $Token->id = $user_has_token->id;
         $Token->update();
     }
     //el
     return $Token->token;
 }