public function register() { $user = new Users(); $user->attributes = $this->attributes; $salt = md5(uniqid() . time()); $user->email = $this->email; $user->salt = $salt; $user->pass = crypt(trim($this->pass) . $salt); if ($user->validate() && $user->save()) { if (!Settings::model()->getValue('mail_confirm')) { $user->status = 1; $user->save(); return 1; } Yii::import('ext.YiiMailer.YiiMailer'); $code = md5(md5($user->pass . $user->email)); $mail = new YiiMailer(); $mail->setFrom(Settings::model()->getValue('register')); $mail->setTo($user->email); $mail->setSubject(Yii::t('register', 'Account activation')); $mail->setBody(Yii::t('register', "Hello {nick},<br/><br/>Your activation code: {code}<br/>{link}", array('{nick}' => $user->nick, '{code}' => $code, '{link}' => Yii::app()->createAbsoluteUrl('site/confirm', array('user' => $user->nick, 'code' => $code))))); $mail->send(); return 1; } }
public function sendEmail() { $this->user_model->password_reset_code = Common::generateSalt(); $this->user_model->password_reset_request_date = date('Y-m-d H:i:s'); $this->user_model->save(false); $template = SettingsEmailTemplate::model()->getRow('*', '`key`=:t1', array(':t1' => SettingsEmailTemplate::KEY_FORGOT_PASSWORD)); if (empty($template)) { return FALSE; } //placeholders : {name},{link} $body = Common::myStringReplace($template['body'], array('{name}' => Person::model()->get($this->user_model->id, 'CONCAT(first_name," ",last_name)'), '{link}' => Yii::app()->createAbsoluteUrl('auth/default/resetPassword', array('id' => $this->user_model->id, 'token' => $this->user_model->password_reset_code)))); //$from, $this->user_model->email, $template->title, $template->body, true MsgEmailOutbox::model()->push(array('from_name' => Yii::app()->settings->get(Constants::CATEGORY_GENERAL, Constants::KEY_SITE_NAME, Yii::app()->name), 'from_email' => $template['from'], 'to_email' => $this->user_model->email, 'subject' => $template['subject'], 'message' => $body)); }
public function actionCreate() { $model = new Users(); if (isset($_POST) && !empty($_POST)) { foreach ($_POST as $k => $v) { // if ($k == "password") { // $crypt = new bCrypt(); // $v = $crypt->hash($v); // } $_POST['Users'][$k] = $v; } $model->attributes = $_POST['Users']; $msg = "User gagal disimpan"; if ($model->save()) { $status = true; $msg = "User berhasil di simpan dengan id " . $model->id; } else { $status = false; } if (Yii::app()->request->isAjaxRequest) { echo CJSON::encode(array('success' => $status, 'msg' => $msg)); Yii::app()->end(); } else { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
public function actionCreate($id = '') { if ($id) { $this->checkPower('updateUser'); $model = Users::model()->findByPk($id); if (!$model) { $this->message(0, '您所编辑的用户不存在'); } $isNew = false; } else { $this->checkPower('addUser'); $model = new Users(); $isNew = true; } if (isset($_POST['Users'])) { if ($isNew || md5($_POST['Users']['password']) != $model->password) { $_POST['Users']['password'] = md5($_POST['Users']['password']); } $model->attributes = $_POST['Users']; if ($model->save()) { $this->redirect(array('users/index')); } } $this->render('create', array('model' => $model)); }
private function setCookie(Users $user) { $token = SecurityFacade::getToken(); $user->save(['remember_token' => $token]); setcookie('auth[email]', CryptFacade::encrypt($user->email), Carbon::now()->addDay(15)->timestamp); setcookie('auth[token]', CryptFacade::encrypt($token), Carbon::now()->addDay(15)->timestamp); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'index' page. */ public function actionCreateUser() { Yii::log("actionCreate called", "trace", self::LOG_CAT); $cancelLink = $this->createUrl('site/login'); $model = new Users(); if (isset($_POST['Users'])) { $model->attributes = $_POST['Users']; $model->roles = $_POST['Users']['roles']; if ($model->validate("insert")) { if ($model->save() && $model->saveRoles($model->userId, "create")) { // send the user the email link: $toMailName = $model->userName; $email = $model->email; // construct data and set expiry to 24 hrs $resetEncrypt = base64_encode($email . ",resetTrue," . (strtotime(date("H:i:s")) + 86400)); $passwordUrl = "http://" . $_SERVER["HTTP_HOST"] . Yii::app()->request->baseUrl . "/index.php/site/changepassword?data={$resetEncrypt}" . "&redirect_uri=" . $cancelLink; $mail = new TTMailer(); $subject = Yii::t('translation', 'User created'); $altBody = Yii::t('translation', 'To view the message, please use an HTML compatible email viewer!'); $message = Yii::t('translation', 'Dear ') . $toMailName . ',<br /><br />' . Yii::t('translation', 'your user account has been created, please visit '); $message .= '<a href="' . $passwordUrl . '">' . $passwordUrl . '</a>' . Yii::t('translation', ' to activate it and set a new password. ') . '<p></p>' . Yii::t('translation', 'This message was automatically generated.') . '<br />' . Yii::t('translation', ' If you think it was sent incorrectly, ') . Yii::t('translation', 'please contact your administrator.'); //if mail is not sent successfully issue appropriate message if (!$mail->ttSendMail($subject, $altBody, $message, $email, $toMailName)) { Yii::log("Error in sending the password to the user", "error", self::LOG_CAT); $msg = Yii::t('translation', "Error in sending the password to the user"); return $msg; } Yii::app()->user->setFlash('success', "User successfully created."); $this->redirect(array('users/index')); } } } $this->render('create', array('model' => $model)); }
public function indexAction() { if ($this->request->isPost()) { $username = $this->request->getPost('username', 'alphanum'); $email = $this->request->getPost('email', 'email'); $password = $this->request->getPost('password'); $name = $this->request->getPost('name'); $phone = $this->request->getPost('phone'); $user = new Users(); $user->username = $username; $user->email = $email; $user->password = sha1($password); $user->name = $name; $user->created_at = new Phalcon\Db\RawValue('now()'); $user->active = 'Y'; $user->class = '1'; $user->phone = $phone; if ($user->save() == false) { foreach ($user->getMessages() as $message) { $this->flash->error((string) $message); } } else { $this->tag->setDefault('email', ''); $this->tag->setDefault('password', ''); $this->flash->success('Спасибо за регистрацию, пожалуйста войдите в вашу учетную запись'); return $this->view->pick("login/index"); } } }
public function registerAction() { if ($this->request->isPost()) { $name = $this->request->getPost('name', 'string'); $username = $this->request->getPost('username', 'string'); $email = $this->request->getPost('email', 'email'); $password = $this->request->getPost('password'); $repeatPassword = $this->request->getPost('repeatPassword'); if ($password != $repeatPassword) { Flash::error((string) $message, 'alert alert-error'); return false; } $name = strip_tags($name); $username = strip_tags($username); $user = new Users(); $user->username = $username; $user->password = sha1($password); $user->name = $name; $user->email = $email; $user->created_at = new Phalcon_Db_RawValue('now()'); $user->active = 'Y'; if ($user->save() == false) { foreach ($user->getMessages() as $message) { Flash::error((string) $message, 'alert alert-error'); } } else { Tag::setDefault('email', ''); Tag::setDefault('password', ''); Flash::success('Thanks for sign-up, please log-in to start generating invoices', 'alert alert-success'); return $this->_forward('session/index'); } } }
/** * Action to register a new user */ public function indexAction() { $form = new RegisterForm(); if ($this->request->isPost()) { $name = $this->request->getPost('name', array('string', 'striptags')); $username = $this->request->getPost('username', 'alphanum'); $email = $this->request->getPost('email', 'email'); $password = $this->request->getPost('password'); $repeatPassword = $this->request->getPost('repeatPassword'); if ($password != $repeatPassword) { $this->flash->error('Passwords are different'); return false; } $user = new Users(); $user->username = $username; $user->password = sha1($password); $user->name = $name; $user->email = $email; $user->created_at = new Phalcon\Db\RawValue('now()'); $user->active = 'Y'; $user->key = md5($email); if ($user->save() == false) { foreach ($user->getMessages() as $message) { $this->flash->error((string) $message); } } else { $this->tag->setDefault('email', ''); $this->tag->setDefault('password', ''); $this->flash->success('Спасибо за регисрация. Пожалуйста залогинтесь для использования API'); return $this->forward('session/index'); } } $this->view->form = $form; }
public function add($phone, $addate) { $bean = new Users(); $bean->user_name = $phone; $bean->addate = $addate; return $bean->save(); }
/** * [POST]アカウントの登録メゾット * * Endpoint POST /auth/signup * * @access public * @return JSON Responce */ public function signupAction() { $post = ['name' => true, 'password' => true, 'screen_name' => true, 'other_profile' => false]; if ($this->_getPost($post)) { $this->_status['response']['status'] = false; $this->_status['response']['code'] = 201; $this->_status['response']['detail'] = $post['empty']; } if ($this->_status['response']['status'] && !$this->_checkName($this->_post['name'], $detail)) { $this->_status['response']['status'] = false; $this->_status['response']['code'] = 205; $this->_status['response']['detail'] = $detail; } if (!$this->_status['response']['status']) { return $this->response->setJsonContent($this->_status); } $profile = empty($this->_post['other_profile']) ? serialize([]) : serialize(json_decode($this->_post['other_profile'], true)); $users = new Users(); $users->assign(['name' => $this->_post['name'], 'password' => $this->security->hash($this->_post['password']), 'screen_name' => $this->_post['screen_name'], 'other_profile' => $profile]); if (!$users->save()) { $this->_status['response']['status'] = false; $this->_status['response']['code'] = 102; return $this->response->setJsonContent($this->_status); } return $this->response->setJsonContent($this->_status); }
public function loginFbAction() { $response = new ApiResponse(); if ($this->request->isPost()) { $fbId = $this->request->getPost('fbId'); $username = $this->request->getPost('username'); $email = $this->request->getPost('email'); $avatar = $this->request->getPost('avatar'); $user = Users::findFirstByFbId($fbId); if ($user == true) { $response->setResponseMessage('Login successfully!'); return $response; } else { $user = new Users(); $user->id = uniqid(); $user->fbId = $fbId; $user->avatar = $avatar; $user->username = $username; $user->email = $email; try { if ($user->save() == false) { $response->setResponseError(implode(', ', $user->getMessages())); } else { $response->setResponseMessage('Register successfully!'); } } catch (PDOException $e) { $response->setResponseError($e->getMessage()); } } } else { $response->setResponseError('Wrong HTTP Method'); } return $response; }
public function actionRegister() { if (!Yii::app()->user->isGuest) { $this->redirect(array('site/index')); } $model = new Users(); if (isset($_POST['Users'])) { $model->CreatedDate = date('Y-m-d H:i:s'); $model->UserId = $this->getRandomNumber(); $model->ActivationCode = $this->generateRandomString(15); $model->attributes = $_POST['Users']; if ($model->save()) { $message = Messages::model()->mailHeader(); $message .= '<p>Dear ' . $model->UserName . '</p>'; $message .= 'Thank you for registering with Getweiss.com'; $message .= '<p>Please click the link below to activate your account</p>'; $message .= '<p><a style="color:#FFF; text-decoration:none" href="' . Yii::app()->getBaseUrl(true) . '/site/activate/?ac=' . $model->ActivationCode . '">' . Yii::app()->getBaseUrl(true) . '/site/activate/?ac=' . $model->ActivationCode . '</a></p>'; $message .= 'Regards<br/>Getweiss.com.'; $message .= Messages::model()->mailFooter(); // Messages::model()->sendMail('Get Weiss', 'Activation', Yii::app()->params['adminEmail'], $model->EmailAddress, $message); $adminmessage = Messages::model()->mailHeader(); $adminmessage .= 'New User Registered in Getweiss.com'; $adminmessage .= '<p><u>Name</u>: ' . $model->UserName . '</p>'; $adminmessage .= '<p><u>Email</u>: ' . $model->EmailAddress . '</p>'; $adminmessage .= Messages::model()->mailFooter(); //Messages::model()->sendMail($model->UserName, 'New User Registration', $model->EmailAddress, Yii::app()->params['adminEmail'], $adminmessage); $this->redirect(array('index', 'msg' => 'success')); } } $this->render('index', array('model' => $model)); }
/** * 注册方法 * 完成数据的插入 * @return boolean whether register is successful */ public function register() { //将已经验证成功的数据插入数据库 if (!$this->hasErrors()) { $user = new Users(); $user->username = $this->username; $user->email = $this->email; $user->salt = Help::fetchSalt(); $user->password = md5(md5($this->password) . $user->salt); $user->reg_ip = Yii::app()->request->userHostAddress; $user->last_ip = Yii::app()->request->userHostAddress; $user->reg_time = time(); $user->last_login = time(); if (!$user->save()) { return false; } } //实行登入操作 if ($this->_identity === null) { $this->_identity = new UserIdentity($this->email, $this->password); $this->_identity->authenticate(); } if ($this->_identity->errorCode === UserIdentity::ERROR_NONE) { Yii::app()->user->login($this->_identity); return true; } else { return false; } }
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param PropelPDO $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(PropelPDO $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their coresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aUsers !== null) { if ($this->aUsers->isModified() || $this->aUsers->isNew()) { $affectedRows += $this->aUsers->save($con); } $this->setUsers($this->aUsers); } // If this object has been modified, then save it to the database. if ($this->isModified()) { if ($this->isNew()) { $pk = UserInformationPeer::doInsert($this, $con); $affectedRows += 1; // we are assuming that there is only 1 row per doInsert() which // should always be true here (even though technically // BasePeer::doInsert() can insert multiple rows). $this->setNew(false); } else { $affectedRows += UserInformationPeer::doUpdate($this, $con); } $this->resetModified(); // [HL] After being saved an object is no longer 'modified' } $this->alreadyInSave = false; } return $affectedRows; }
public function actionAddUser() { $model = new Users(); if (isset($_REQUEST['user_name']) && isset($_REQUEST['user_email'])) { $model->user_created_by_id = 0; $model->user_email = $_REQUEST['user_email']; $model->user_name = $_REQUEST['user_name']; $model->user_role_type = 5; $passwod = Utils::getRandomPassword(); $model->user_password = md5($passwod); $userdata['user_name'] = $model->user_name; $userdata['user_email'] = $model->user_email; $userdata['user_password'] = $passwod; $userdata['login_url'] = Utils::getBaseUrl() . "/auth"; $template = Template::getTemplate('log-in_mail_template'); $subject = $template->template_subject; $message = $template->template_content; $subject = $this->replace($userdata, $subject); $message = $this->replace($userdata, $message); if ($model->save()) { $this->SendMail($model->user_email, $model->user_name, $subject, $message); echo json_encode(array("error" => FALSE, 'error_code' => "200", "Message" => "User added successfully.")); } else { echo json_encode(array("error" => TRUE, 'error_code' => "201", "Message" => "User Email is already Registor.")); } } else { echo json_encode(array("error" => TRUE, 'error_code' => "203", "Message" => "User name & Email are required.")); } }
public function indexAction() { if ($this->request->isPost()) { $register = new Users(); $register->id = UUID::v4(); $register->password = $this->security->hash($this->request->getPost('password')); $register->phonenumber = $this->request->getPost('phonenumber'); $register->email = $this->request->getPost('email'); $register->name = $this->request->getPost('name'); $register->created_date = Carbon::now()->now()->toDateTimeString(); $register->updated_date = Carbon::now()->now()->toDateTimeString(); $user = Users::findFirstByEmail($register->email); if ($user) { $this->flash->error("can not register, User " . $register->email . " Alredy Registerd! "); return true; } if ($register->save() === true) { $this->session->set('user_name', $register->name); $this->session->set('user_email', $register->email); $this->session->set('user_id', $register->id); $this->flash->success("Your " . $register->email . " has been registered Please Login for booking court"); $this->response->redirect('dashboard'); } } }
/** * Action to register a new user */ public function indexAction() { $form = new RegisterForm(); if ($this->request->isPost()) { $name = $this->request->getPost('name', array('string', 'striptags')); $username = $this->request->getPost('username', 'alphanum'); $email = $this->request->getPost('email', 'email'); $password = $this->request->getPost('password'); $repeatPassword = $this->request->getPost('repeatPassword'); if ($password != $repeatPassword) { $this->flash->error('Passwords are diferent'); return false; } $user = new Users(); $user->username = $username; $user->password = sha1($password); $user->name = $name; $user->email = $email; $user->created_at = new Phalcon\Db\RawValue('now()'); $user->active = 'Y'; if ($user->save() == false) { foreach ($user->getMessages() as $message) { $this->flash->error((string) $message); } } else { $this->tag->setDefault('email', ''); $this->tag->setDefault('password', ''); $this->flash->success('Thanks for sign-up, please log-in to start generating invoices'); return $this->forward('session/index'); } } $this->view->form = $form; }
public function save_user($user_data) { $user = new Users(); $user->fromArray($user_data); $user->save(); return TRUE; }
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param PropelPDO $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(PropelPDO $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their coresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aRides !== null) { if ($this->aRides->isModified() || $this->aRides->isNew()) { $affectedRows += $this->aRides->save($con); } $this->setRides($this->aRides); } if ($this->aUsers !== null) { if ($this->aUsers->isModified() || $this->aUsers->isNew()) { $affectedRows += $this->aUsers->save($con); } $this->setUsers($this->aUsers); } if ($this->isNew()) { $this->modifiedColumns[] = UserRidesPeer::USER_RIDE_ID; } // If this object has been modified, then save it to the database. if ($this->isModified()) { if ($this->isNew()) { $pk = UserRidesPeer::doInsert($this, $con); $affectedRows += 1; // we are assuming that there is only 1 row per doInsert() which // should always be true here (even though technically // BasePeer::doInsert() can insert multiple rows). $this->setUserRideId($pk); //[IMV] update autoincrement primary key $this->setNew(false); } else { $affectedRows += UserRidesPeer::doUpdate($this, $con); } $this->resetModified(); // [HL] After being saved an object is no longer 'modified' } if ($this->collUserRideMaps !== null) { foreach ($this->collUserRideMaps as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collUserStatss !== null) { foreach ($this->collUserStatss as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } $this->alreadyInSave = false; } return $affectedRows; }
public function actionAdd() { $this->layout = '//layouts/admin'; $this->pageTitle = 'Новый пользователь'; $this->breadcrumbs = array('Пользователи' => array('/admin/users'), 'Новый пользователь'); $success = false; if (isset($_POST['data'])) { $model = new Users(); $dataArray = $_POST['data']; $dataArray['reg_date'] = isset($dataArray['reg_date']) ? strtotime($dataArray['reg_date']) : time(); if (isset($dataArray['password']) && $dataArray['password']) { $dataArray['password'] = md5($model->login . $dataArray['password']); } $model->setAttributes($dataArray); if ($model->save()) { $success = true; } } if ($success) { $this->redirect("/admin/users"); } if (!isset($model) || !is_object($model)) { $model = new Users(); } $this->render('add', array('model' => $model, 'errors' => $model->errors)); }
/** * Create new user */ public function addAction() { // check API authentication if (!$this->authenticateRequest()) { return $this->processResponse(array('status' => 401, 'payload' => array('status' => 'failure', 'data' => null, 'error' => array('code' => 401, 'message' => 'API authentication failed')))); } // verify token if (!$this->verifyCsrfToken()) { return $this->processResponse(array('status' => 401, 'payload' => array('status' => 'failure', 'data' => null, 'error' => array('code' => 401, 'message' => 'Token validation failed')))); } // get HTTP entity body $httpContent = file_get_contents('php://input'); if (empty($httpContent)) { return $this->processResponse(array('status' => 404, 'payload' => array('status' => 'failure', 'data' => null, 'error' => array('code' => 404, 'message' => 'User information not provided')))); } $data = json_decode($httpContent); // create user $user = new Users(); $user->name = htmlentities($data->name); $user->createdDate = new MongoDate(); $user->modifiedDate = new MongoDate(); if ($user->save() == false) { foreach ($user->getMessages() as $message) { $this->logger->log(sprintf('NAMESPACE=user MESSAGE=%s', $message), \Phalcon\Logger::ERROR); } return $this->processResponse(array('status' => 404, 'payload' => array('status' => 'failure', 'data' => null, 'error' => array('code' => 404, 'message' => 'Failed to create user')))); } else { return $this->processResponse(array('status' => 201, 'payload' => array('status' => 'success', 'data' => json_encode($user), 'error' => null))); } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { // echo "lllll"; // die; $model = new Users(); if (isset($_POST['Users'])) { // var_dump($_POST); $salt = bin2hex(openssl_random_pseudo_bytes(22)); // echo "salt: ".$salt; $encrypted_password = md5($_POST['Users']['password'] . $salt); $_POST['Users']['password'] = $encrypted_password; $_POST['Users']['salt'] = $salt; // $_POST['Users']['created_at'] = date('Y-m-d H:i:s'); // $_POST['Users']['updated_at'] = date('Y-m-d H:i:s'); // var_dump($_POST); $model->attributes = $_POST['Users']; if ($model->save()) { // echo "ccccc"; // die; if ($model->login()) { // echo "ddddd"; // die; $record = Users::model()->findByAttributes(array('username' => $_POST['Users']['username'])); Yii::app()->session['uid'] = $record['id']; Yii::app()->session['username'] = $record['username']; $this->redirect('/index.php?r=posts/index'); } } } $this->render('create', array('model' => $model)); }
/** * Logs in the user using the given username and password in the model. * @return boolean whether login is successful */ public function save() { $user = new Users(); $user->setAttributes($this->attributes); $user->setAttribute("password", BaseTool::ENPWD($this->password)); if ($user->validate() && $user->save()) { $accountarray = array('user_id' => Yii::app()->db->getLastInsertID(), 'total' => 0, 'use_money' => 0, 'no_use_money' => 0, 'newworth' => 0); $newAccount = new Account(); $newAccount->setAttributes($accountarray); $newAccount->save(); //发送邮件 $activecode = BaseTool::getActiveMailCode($this->username); $message = MailTemplet::getActiveEmail($this->username, $activecode); $mail = Yii::app()->Smtpmail; $mail->SetFrom(Yii::app()->params['adminEmail']); $mail->Subject = "好帮贷测试邮件"; $mail->MsgHTML($message); $mail->AddAddress($this->email); if ($mail->Send()) { $user->updateAll(array("regtaken" => $activecode, "regativetime" => time() + 60 * 60), "username=:username", array(":username" => $this->username)); } Yii::import("application.models.form.LoginForm", true); $loginform = new LoginForm(); $loginarray = array('rememberMe' => false, 'username' => $this->username, 'password' => $this->password); $loginform->setAttributes($loginarray); if ($loginform->validate() && $loginform->login()) { } return true; } else { $usererror = $user->errors; $this->addError("username", current(current($usererror))); return false; } }
public function post_index() { $new = new Users(); $new->save(); $response = array('success' => true, 'data' => array('id' => $new->id)); $json = json_encode($response); return $json; }
public function create_user($username, $email, $password) { $usuario = new Users(); $usuario->setUsername($username); $usuario->setEmail($email); $usuario->setPassword($password); $usuario->save(); }
public function actionStep2() { $model = new Users('step2'); /*if(isset($_POST['ajax']) && $_POST['ajax']==='users-form') //тут ajax-валидация { $model->setScenario('active'); $model->verifyCode = $_POST['Users']['verifyCode']; echo CActiveForm::validate($model); Yii::app()->end(); }*/ if (isset($_POST['Users'])) { //print_r($_POST); exit(); $model->name = $_POST['Users']['name']; //$model->login = $_POST['Users']['login']; $model->email = $_POST['Users']['email']; $model->password = $_POST['Users']['password']; $model->member = $_POST['Users']['member']; //$model->verifyCode = $_POST['Users']['verifyCode']; $model->tos = $_POST['Users']['tos']; if ($_POST['Users']['member'] == 0) { $model->member_type = 'client'; } //$model->scenario = 'registerwcaptcha'; if ($model->validate()) { // and here is the actual HACKY part $model->scenario = 'step2'; if ($model->save()) { if (!is_dir($_SERVER['DOCUMENT_ROOT'] . '/users/' . $model->id)) { mkdir($_SERVER['DOCUMENT_ROOT'] . '/users/' . $model->id); } $key = ''; $key = hash('md5', 'uid=' . $model->id . '&activate=1'); $name = '=?UTF-8?B?' . base64_encode($model->name) . '?='; $subject = '=?UTF-8?B?' . base64_encode('Регистрация на НМ') . '?='; $headers = "MIME-Version: 1.0\r\n" . "Content-Type: text/plain; charset=UTF-8"; $msg = "Подтвердите регистрацию! Ссылка - <a href='" . $this->createUrl('/register/confirm', array('uid' => $model->id, 'key' => $key)) . "'>подтвердить</a>\n <br />Если Ваш браузер не открывает ссылку, скопируйте ее адрес в браузер - " . $this->createUrl('/register/confirm', array('uid' => $model->id, 'key' => $key)); //if(mail($model->email,$subject,$msg,$headers)) { if (Users::mailsend($model->email, '*****@*****.**', $subject, $msg)) { Yii::app()->user->setFlash('create', 'На Ваш email отправлено письмо для подтверждения регистрации.'); //$this->render('activate',array('model'=>$model)); //sleep(100); //$this->redirect(array('/profile/view','id'=>$model->id)); } else { throw new CHttpException(500, 'Error send mail().'); } $this->render('activate', array('model' => $model)); } } else { /*echo "not valid"; echo CActiveForm::validate($model); Yii::app()->end();*/ $this->render('step2', array('model' => $model)); } } else { $this->render('step2', array('model' => $model)); } }
public function actionAddAdminUser() { $auth = Yii::app()->authManager; $user = new Users(); $user->u_name = 'admin'; $user->u_pass = '******'; $user->u_email = '*****@*****.**'; $user->u_role = 'admin'; $user->save(); }
public function testUserCreate() { $model = new Users(); $model->attributes = array('email' => '*****@*****.**', 'password' => 'example_password', 'username' => 'example_user2', 'user_role' => '9', 'status' => '1'); // Verify that we can save a new record $this->assertTrue($model->save()); // Verify that bcrypt password validation passes $this->assertTrue(password_verify('example_password', $model->password)); $this->assertTrue($model->delete()); }
public function registerAction() { $user = new Users(); $login = $this->request->getPost('login'); $password = $this->request->getPost('password'); $user->login = $login; //Store the password hashed $user->password = $this->security->hash($password); $user->save(); }