Exemplo n.º 1
0
 /**
  * This is common user register algorithm.
  * It validates POST data and registers user.
  */
 public function postRegister()
 {
     $email = Request::post('email', 'email');
     $pass = Request::post('password');
     $pass2 = Request::post('password2');
     // Validate POST data
     if (!$this->validateData($email, $pass, $pass2)) {
         // No need to proceed. Just return, all errors are in Messenger stack
         return;
     }
     // Register user
     $res = UserModel::register($email, $pass2);
     if (!$res['success']) {
         if ($res['error'] == 'exists') {
             Messenger::error('An account with that email already exists. Please try again. if you lost your password, click <a href="/user?action=reset&email=' . urlencode($email) . '">here</a>');
             return $this->getRegister();
         } else {
             Messenger::error('User could not be created');
             return $this->getRegister();
         }
     }
     // See if they are being added to a specific list.
     $default_list = Configuration::get('mailer.default_list', 0);
     $mailing_list = Request::post('list_id', 'int', null, $default_list);
     if (!empty($mailing_list)) {
         $user = UserModel::loadByEmail($email);
         $user->subscribe($mailing_list);
     }
     $this->loginRedirect();
 }
Exemplo n.º 2
0
 public function postRegister()
 {
     $email = Request::post('email', 'email');
     $pass = Request::post('password');
     // Validate POST data
     if (!$this->validateData($email, $pass)) {
         // Immediately output all the errors
         Output::error("Invalid Data");
     }
     // Register user
     $res = UserModel::register($email, $pass);
     if ($res['success']) {
         Output::json($res['data']);
     } else {
         Output::error($res['error']);
     }
 }