public function get() { $this->tpl = 'account/welcome.php'; if ($this->user->isOK()) { $this->alert('You don not need re-send verify mail'); } if (!$this->user->email) { $this->alert("No email found, can not reactive!"); } SendVerifyEmail::perform($this->user); }
public function post() { $is_verify_user = $this->app->verify_user; // Check email if (!filter_var($this->input->data('email'), FILTER_VALIDATE_EMAIL)) { $this->alert('Email format is wrong'); } // Check user name rule if (!preg_match("/^[\\w]{4,20}\$/", $this->input->data('name'))) { $this->alert('User name only use a-z and 0-9, length must be 6-20'); } // Check password length if (strlen($this->input->data('password')) < 6) { $this->alert('Password length must be great than or equal 6'); } // Check if exists user name if (Model::factory('User')->where('name', $this->input->data('name'))->find_one()) { $this->alert('User already exists'); } // Check if exists user email if (Model::factory('User')->where('email', $this->input->data('email'))->find_one()) { $this->alert('Email already taken'); } // Create user /** @var $user \Model\User */ $user = Model::factory('User')->create(array('name' => $this->input->data('name'), 'password' => Crypt::makePassword($this->input->data('password'), $this->app->password_salt), 'email' => $this->input->data('email'), 'bio' => $this->input->data('bio'))); // If disable verify_user will set user verified automatic. if (!$is_verify_user) { $user->setVerified(); } try { ORM::get_db()->beginTransaction(); if (!$user->save()) { $this->alert('User create error'); } ORM::get_db()->commit(); } catch (\PDOException $e) { $this->alert('User register error because of the bad database'); //@TODO log ORM::get_db()->rollback(); } // login when success $this->input->session('login', $user->id); // Check if verify user if ($is_verify_user) { // Send verify email SendVerifyEmail::perform($user); $this->redirect('/account/welcome'); } else { $this->redirect('/'); } }
public function post(Input $req) { // Check email if (!filter_var($req->data('email'), FILTER_VALIDATE_EMAIL)) { $this->alert('Email format is wrong'); } if ($password = $req->data('password')) { // Check password length if (strlen($req->data('password')) < 6) { $this->alert('Password length must be great than or equal 6'); } if ($req->data('password') != $req->data('re_password')) { $this->alert('Password dose not match'); } } $this->user->set('bio', $req->data('bio')); // Change password if ($password) { $this->user->password = Crypt::makePassword($password, $this->app->password_salt); } $send = false; // Change email if ($this->user->email != $req->data('email')) { // Check if exists user email if (Model::factory('User')->where('email', $req->data('email'))->find_one()) { $this->alert('Email already taken'); } $this->user->email = $req->data('email'); $this->user->status = User::UNVERIFIED; $send = true; } try { if (!$this->user->save()) { $this->alert('User create error'); } } catch (\PDOException $e) { $this->alert('User register error because of the bad database'); } if ($send) { // Send verify email SendVerifyEmail::perform($this->user); } $this->redirect('/u/' . $this->user->id); }