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('/'); } }
/** * Do the migration */ public function up() { $query = $this->container['pdo']->query('SELECT * FROM `user`'); $password = array(); while ($row = $query->fetch(\PDO::FETCH_ASSOC)) { if (strlen($row['password']) < 40) { $password[$row['id']] = Crypt::makePassword($row['password'], $this->container['app']->password_salt); } } foreach ($password as $id => $pass) { $this->container['pdo']->exec("UPDATE `user` SET `password` = '{$pass}' WHERE `id` = '{$id}'"); } }
public function post() { if (filter_var($this->input->data('name'), FILTER_VALIDATE_EMAIL)) { if (!($user = Model::factory('User')->where('email', $this->input->data('name'))->find_one())) { $this->alert('User email not found'); } } else { if (!($user = Model::factory('User')->where('name', $this->input->data('name'))->find_one())) { $this->alert('User name not found'); } } if ($user->password != Crypt::makePassword($this->input->data('password'), $this->app->password_salt)) { $this->alert('User name and password is not match'); } $this->input->session('login', $user->id); $this->redirect($this->input->query('continue') ? $this->input->query('continue') : '/'); }
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); }
* 生成配置 */ $config['site'] += $default_site; $config['database'] = $db + $default_db; $config += $default_config; file_put_contents(BASE_DIR . '/config/env', 'production'); file_put_contents(BASE_DIR . '/config/production.php', '<?php return ' . var_export($config, true) . ';'); /** * 升级数据库 */ $command = 'PAGON_ENV=production /usr/bin/env php ' . BASE_DIR . '/bin/task db:migrate 2>&1'; shell_exec($command); /** * 生成用户 */ $password = \Helper\Crypt::makePassword($admin['password'], $config['password_salt']); try { $pdo->exec("INSERT INTO `user` (`name`, `password`, `status`, `created_at`) VALUES ('{$admin['username']}', '{$password}', 1, '" . date('Y-m-d H:i:s') . "')"); } catch (\PDOException $e) { echo "Install failed"; return; } if (is_writable(__DIR__) && @rmdir(__DIR__)) { echo "Install OK!"; } else { echo "Install OK! but " . __DIR__ . ' is not delete, plz delete manually.'; } echo " Redirecting... <script type='text/javascript'>window.setTimeout(function(){window.location.href='" . url('/') . "';}, 3000);</script>"; }); $app->all('/^.+$/', function ($req, $res) { $res->redirect(url('/'));