/** * processAction * * Member registration process * * @return null */ public function processAction() { // set json context \View::setOutputContext('json'); \View::lockOutputContext(); // validate form $registerForm = new forms\RegisterForm(); $registerForm->validate(); if (!$registerForm->isValid()) { throw new \MemberErrorException(array('title' => \View::$language->register_error, 'description' => \View::$language->register_proc_err_descr, 'form_messages' => $registerForm->getMessages())); } $userData = $registerForm->getData(); // set new user defaults $hCnf = \App::getConfig('hosts'); $mCnf = \App::getConfig('member-defaults'); $pass = \common\CryptHelper::generateHash($userData->password); $userData->group_id = $mCnf->group_id; $userData->cookie = \common\HashHelper::getUniqueKey(); $userData->password = $pass; $userData->time_zone = $mCnf->time_zone; $userData->status = $mCnf->status; $userData->activation_hash = \common\HashHelper::getUniqueKey(); $userData->avatar = '//' . $hCnf->st . $mCnf->avatar; // create a new user $UserModel = \App::getInstance('common\\UserModel'); $UserModel->createUser($userData); // TODO send email notification of account activation \App::dump($userData); // redirect to complete page \Storage::write('__register_complete', true); throw new \MemberSuccessException(array('redirection' => '/user/register/complete')); }
/** * trySignIn * * Try sign in process * * @param StdClass $signInData Member sign in data * @return null */ public static function trySignIn(\StdClass $signInData) { \View::addLanguageItem('SignInHelper'); $memberData = \DBI::getConnection('master')->sendQuery('SELECT cookie, password, status FROM members WHERE email = :email OR login = :login', array(':email' => $signInData->login, ':login' => $signInData->login))->fetch(\PDO::FETCH_OBJ); // member data not found if (!$memberData) { throw new \MemberErrorException(array('title' => \View::$language->sign_in_helper_error, 'description' => \View::$language->sign_in_helper_login_or_password_invalid)); } // compare password $hasSamePassword = \common\CryptHelper::verifyHash($signInData->password, $memberData->password); if (!$hasSamePassword) { throw new \MemberErrorException(array('title' => \View::$language->sign_in_helper_error, 'description' => \View::$language->sign_in_helper_login_or_password_invalid)); } // sign in success $cnf = \App::getConfig('main')->system; $exp = time() + $cnf->cookie_expires_time; setcookie($cnf->cookie_name, $memberData->cookie, $exp, '/'); throw new \MemberSuccessException(array('title' => \View::$language->sign_in_helper_success, 'description' => \View::$language->sign_in_helper_success_description, 'redirection' => '/')); }