public function testValidation() { $obj = new UserModel(); $obj->email = '*****@*****.**'; $v = $obj->validate(); $this->assertCount(0, $v, validationErrorsToString($v)); }
/** * registering the new user */ public function registerAction() { parent::render('signup'); if (isset($_POST['submit'])) { session_start(); $_SESSION['user'] = $_POST['username']; $reg = new UserModel(); if ($reg->validate() === true) { if ($reg->insertUser() === true) { parent::redirect("User", "userPage"); } else { parent::redirect("User", "fail"); } } } }
public function actionUserCreate() { $model = new UserModel(); $group = GroupModel::model()->findall(); foreach ($group as $v) { $groupList[$v->group_id] = $v->name; } if (isset($_POST['UserModel'])) { // 收集用户输入的数据 $model->attributes = $_POST['UserModel']; $model->scenario = 'create'; if ($model->validate()) { //检查用户是否重复 $model->pswd = md5($_POST['UserModel']['pswd']); $model->repswd = md5($_POST['UserModel']['repswd']); $model->save(); $this->redirect(array('group/user')); } } $this->render('userCreate', array('model' => $model, 'group' => $groupList)); }
public function actionIndex() { $model = new UserModel(); if (isset($_POST['UserModel'])) { $model->attributes = $_POST['UserModel']; $model->username = $model->email; if ($model->validate()) { $record = UserModel::model()->findByAttributes(array('email' => $model->email)); if ($record !== null) { $this->render('error', array('type' => 'repeate')); exit; } else { if ($model->save()) { //$this->redirect(array('style/index','id'=>$model->_id)); $this->redirect(array('login/index')); } $this->refresh(); } } } $this->render('index', array('model' => $model)); }
public function loginAction() { $name = $this->getRequest()->getParam('account'); $password = $this->getRequest()->getParam('password'); $check = $this->getRequest()->getParam('check'); if ($check == 1) { setcookie("account", $name, time() + 86400, "/"); setcookie("password", $password, time() + 86400, "/"); } else { setcookie("account", "null", time() + 86400, "/"); setcookie("password", "null", time() + 86400, "/"); } $User = new UserModel(); $res = $User->validate($name, $password); if (count($res) == 1) { $_SESSION["userinfo"] = $res; $this->view->info = $res; $this->view->cookie = $_COOKIE; $this->_forward('home', 'Home'); } else { $this->_forward('index', 'Index'); } }
/** * Import WP Author into users * * @param mixed $author Author data from WP XML * * @return Null */ protected function _importAuthor($author) { if (!craft()->users->getUserByEmail($author['author_email'])) { if (empty(trim($author['author_first_name']) . trim($author['author_last_name']))) { $author['author_first_name'] = $author['author_login']; } $user = new UserModel(); $user->username = $author['author_login']; $user->firstName = $author['author_first_name']; $user->lastName = $author['author_last_name']; $user->email = $author['author_email']; if (!$user->validate()) { $emailParts = explode('@', $author['author_email']); $user->username = $emailParts[0]; } if (!craft()->users->saveUser($user)) { Craft::log('Couldn’t save the user "' . $author['author_login'] . '"', LogLevel::Warning, true, 'application', 'InstaBlog'); } } else { Craft::log('A User already exists with the email: "' . $author['author_email'] . '"', LogLevel::Info, false, 'application', 'InstaBlog'); } }
public function syncCustomer($xml) { craft()->requireEdition(Craft::Pro); if (!$this->ssoEnabled) { return false; } if (!craft()->systemSettings->getSetting('users', 'allowPublicRegistration')) { FoxyCartPlugin::log('[sso] Unable to save user as allowPublicRegistration is set to false', LogLevel::Error); return false; } foreach ($xml->transactions->transaction as $transaction) { $customerId = (string) $transaction->customer_id; $customerFirstName = (string) $transaction->customer_first_name; $customerLastName = (string) $transaction->customer_last_name; $customerEmail = (string) $transaction->customer_email; $customerPassword = (string) $transaction->customer_password; $customerPasswordHashType = (string) $transaction->customer_password_hash_type; $customerPasswordHashConfig = (string) $transaction->customer_password_hash_config; // Make sure they have the right password algorithm if ($customerPasswordHashType !== "craftcms") { FoxyCartPlugin::log(sprintf('[sso] Unable to save user as FoxyCart password hashing method is set to "%s", needs to be "Craft CMS"', $customerPasswordHashType), LogLevel::Error); return false; } if ($customerPasswordHashConfig != craft()->config->get('blowfishHashCost')) { FoxyCartPlugin::log(sprintf('[sso] Unable to save user due to password encryption algorithm config mismatch. FoxyCart: "%s" - Craft: "%s"', $customerPasswordHashConfig, craft()->config->get('blowfishHashCost')), LogLevel::Error); return false; } // Ignore them if they checked out as a guest if ($customerId != '0') { $isNewUser = false; $user = craft()->users->getUserByUsernameOrEmail($customerEmail); if (!$user) { $user = new UserModel(); $isNewUser = true; } $user->firstName = $customerFirstName; $user->lastName = $customerLastName; if ($isNewUser) { $user->email = $customerEmail; $user->username = $customerEmail; $user->status = UserStatus::Active; } // ToDo: Do we need to raise an onSyncUser event here, or will users.onSaveUser cover it? if ($user->validate(null, false) && craft()->users->saveUser($user)) { // Save their password directly, as there isn't an API to save an already hashed password in Craft $sql = craft()->db->createCommand(); $sql->update('users', array('password' => $customerPassword), 'id=:id', array(':id' => $user->id)); // Save their FoxyCart customer ID $this->saveCustomerId($user, $customerId); // Assign them to a group if ($this->ssoGroup) { craft()->userGroups->assignUserToGroups($user->id, array($this->ssoGroup)); } return true; } else { FoxyCartPlugin::log('[sso] Couldn’t save user from webhook', LogLevel::Error); return false; } } } }
$ResourceModel = new ResourceModel(); $BuildingModel = new BuildingModel(); $LanternModel = new LanternModel(); $GiftModel = new GiftModel(); /* * Main path */ $app->get('/', function (Request $request) use($app, $UsersController) { return $app->redirect('doc/index.html'); }); /* * Users */ $app->get($basePath . '/userInfos', function (Request $request) use($app, $UsersController, $UserModel) { $params = $request->query->all(); $errorMessage = $UserModel->validate($params, "index"); if ($errorMessage) { return Utils::formatErrorMessage(ERROR_BAD_MODEL, $errorMessage); } else { return $UsersController->index($params); } }); $app->get($basePath . '/users/login', function (Request $request) use($app, $UsersController, $UserModel) { $params = $request->query->all(); $errorMessage = $UserModel->validate($params, 'login'); if ($errorMessage) { return Utils::formatErrorMessage(ERROR_BAD_MODEL, $errorMessage); } else { return $UsersController->login($params); } });
/** * 注册后台处理方法 */ public function actionRegister() { $user = new UserModel(); $user->ts_u_phone = $_POST['phone']; $user->ts_u_password = Utils::getUserPassword($_POST['pwd']); $user->ts_u_username = $_POST['username'] ? $_POST['username'] : $_POST['phone']; $user->ts_u_type = 3; $info = array(); if (!$user->validate()) { var_dump($user->getErrors()); exit; $info = array('status' => 2, 'info' => $this->getErrorMessage($user->getErrors())); } else { $user->save(); //$message['id'] = $user->attributes['ts_u_id']; $info = array('status' => 1, 'info' => "注册成功"); } echo json_encode($info); die; }