本文整理汇总了PHP中app\models\User::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP User::validate方法的具体用法?PHP User::validate怎么用?PHP User::validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\User
的用法示例。
在下文中一共展示了User::validate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionRegister
public function actionRegister()
{
$model = new User();
$profile = new Profile();
if ($model->load(Yii::$app->request->getBodyParams(), '') && $model->validate()) {
if ($model->validate()) {
$id = $model->register();
$profile->createProfile($id);
return ['success' => true];
}
} else {
return $model;
}
}
示例2: actionInit
/**
*
*/
public function actionInit()
{
// assign roles
$oAuthManager = \Yii::$app->authManager;
$oAuthManager->removeAll();
// role user
$oRoleUser = $oAuthManager->createRole('user');
$oRoleUser->description = 'Registered user';
$oAuthManager->add($oRoleUser);
// create default users
$aDefaultUser = \Yii::$app->params['aDefaultUser'];
$oSecurity = \Yii::$app->security;
foreach ($aDefaultUser as $sUsername => $aUserData) {
$mUser = User::findOne(['username' => $aUserData['username']]);
if (!$mUser) {
$mUser = new User();
$mUser->username = $sUsername;
$mUser->password = $oSecurity->generatePasswordHash($aUserData['password']);
$mUser->email = $aUserData['email'];
$mUser->authKey = $oSecurity->generateRandomString();
}
if ($mUser->validate()) {
$mUser->save();
// assign role to each
$oAuthManager->assign($oAuthManager->getRole($aUserData['role']), $mUser->id);
}
}
}
示例3: actionCreate
/**
* Creates a new Student model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$student = new Student();
$user = new User();
$person = new Person();
if (Yii::$app->request->post()) {
$params = Yii::$app->request->post();
$person->load($params);
$user->load($params);
$user->password_hash = Yii::$app->getSecurity()->generatePasswordHash($params['User']['password_hash']);
$student->load($params);
if ($person->validate() && $user->validate() && $student->validate()) {
$person->save(false);
$user->person_id = $person->id;
$user->register();
$student->user_id = $user->id;
$student->save();
Yii::$app->session->setFlash('success', 'Se envío un correo de confirmación. Por favor verifique su correo electrónico');
return $this->refresh();
} else {
Yii::$app->session->setFlash('danger', 'Ocurrió ff un error al guardar. Vuelve a intentar');
return $this->refresh();
}
} else {
return $this->render('create', ['student' => $student, 'user' => $user, 'person' => $person]);
}
}
示例4: actionCreate
/**
* Creates a new User model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$modelUser = new User();
$modelProfile = new Profile();
$roles = AuthItem::find()->all();
$arrayRoles = ArrayHelper::map($roles, 'name', 'description');
$regions = Region::find()->all();
$arrayRegions = ArrayHelper::map($regions, 'id', 'name');
if ($modelUser->load(Yii::$app->request->post())) {
if ($modelUser->validate()) {
$modelUser->setPassword($modelUser->password_hash);
if ($modelUser->save(false)) {
$modelProfile->user_id = $modelUser->id;
$modelProfile->worker_name = $modelUser->worker_name;
$modelProfile->telephone = $modelUser->telephone;
$modelProfile->head_position = $modelUser->head_position;
$modelProfile->head_name = $modelUser->head_name;
$modelProfile->region_id = $modelUser->region;
if ($modelProfile->save(false)) {
$auth = Yii::$app->authManager;
$auth->revokeAll($modelUser->id);
$access = $auth->getRole($modelUser->access);
if ($auth->assign($access, $modelUser->id)) {
return $this->redirect(['view', 'id' => $modelUser->id]);
}
}
}
}
}
return $this->render('create', ['model' => $modelUser, 'arrayRoles' => $arrayRoles, 'arrayRegions' => $arrayRegions]);
}
示例5: actionSignup
public function actionSignup()
{
$post = Application::request()->post();
$warning = '';
if (sizeof($post) > 0) {
$model = new User();
$model->load($post);
$validation = $model->validate();
if ($validation) {
$user_id = $model->save();
if ($user_id) {
Application::Identity()->signin($user_id);
$this->redirect('/search');
} else {
$warning = 'Error adding row to DB';
}
} else {
$warning = 'Please enter correct fields values';
}
}
if (!Application::Identity()->check()) {
$this->render('signup.html', ['salt' => Helper::generateCode(15), 'warning' => $warning]);
} else {
$this->redirect('/search');
}
}
示例6: _addOrUpdate
private function _addOrUpdate($params)
{
if ($params['id']) {
$user = User::findOne(['id' => $params['id']]);
if (!$user) {
return ['success' => 0, 'message' => 'No such user exist'];
}
} else {
$user = new User();
}
$user->username = $params['username'];
$user->email = $params['email'];
$user->phone = $params['phone'];
$user->password = $params['password'];
if (!$user->validate()) {
return ['success' => 0, 'message' => $user->getErrors()];
}
if (count($_FILES)) {
$uploader = new FileUploader($_FILES['profile_picture']);
$fileName = md5($user->email . Yii::$app->security->generateRandomString());
$path = Yii::$app->basePath . '/web/images/profile/' . $fileName . '.' . $uploader->extension();
$uploadStatus = $uploader->save($path);
if (!$uploadStatus['success']) {
return ['success' => 0, 'message' => $uploadStatus['error']];
}
$user->profile_picture = $file_name . '.' . $uploader->extension();
}
if (!$user->save()) {
return ['success' => 0, 'message' => 'Some error occurred'];
}
return ['success' => 1, 'payload' => $user];
}
示例7: actionCreate
/**
* Creates a new User model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new User();
if ($model->load(Yii::$app->request->post())) {
if ($model->validate()) {
$model->save();
return $this->redirect(['view', 'id' => $model->id]);
}
}
return $this->render('create', ['model' => $model]);
}
示例8: testRegUser
public function testRegUser()
{
$user = new User();
$user->email = 'test@test.ru';
$user->name = 'test';
$user->setPassword('password');
$user->generateAuthKey();
$this->assertTrue($user->validate());
$this->assertTrue($user->save());
$this->tester->seeInDatabase('users', ['email' => 'test@test.ru', 'name' => 'test']);
}
示例9: actionUser
public function actionUser()
{
$model = new app\models\User();
if ($model->load(Yii::$app->request->post())) {
if ($model->validate()) {
// form inputs are valid, do something here
return;
}
}
return $this->render('user', ['model' => $model]);
}
示例10: actionCreate
public function actionCreate()
{
//TODO: Check rights
$user = new User();
if ($user->load(\yii::$app->request->post()) && $user->validate()) {
$user->password = \yii::$app->getSecurity()->generatePasswordHash($user->password);
$user->save();
\Yii::$app->response->setStatusCode(201);
return $this->actionGet($user->id);
}
return $user->errors;
}
示例11: actionCreate
public function actionCreate()
{
$model = new User();
$model->setAction('admin-insert');
if (isset($_POST['save'])) {
$model->setAttributes($_POST['User']);
if ($model->validate() && $model->adminCreate()) {
Messages::get()->success("User created!");
$this->getRequest()->goToPage('users', 'index');
}
}
$this->assign('model', $model);
}
示例12: actionPost
public function actionPost()
{
if ($userData = $this->container->request->post('User')) {
$user = new User($this->container);
$user->setModelData($userData);
$user->pass = md5($user->pass);
if ($user->validate() && $user->save()) {
$this->redirect('/register/success');
}
$this->redirect('/register/error');
}
$this->redirect('/register');
}
示例13: actionAdd
public function actionAdd()
{
$user = new User();
$user->name = 'simon1';
$user->mail = '432423@qq.com';
$user->password = 'fsfhsdlfh';
//数据验证,在User类中添加rules()对数据进行校验
$user->validate();
if ($user->hasErrors()) {
echo 'your data is error';
die;
}
$user->save();
}
示例14: login
public function login(LoginRequest $request)
{
if ($user = User::validate($request->input())) {
$userId = $user->id;
if ($token = AccessToken::createToken($userId)) {
$message = $this->getMessage('success', ['user_id' => $userId, 'username' => $user->username, 'token' => $token]);
} else {
$message = $this->getMessage('error', [Request::ERROR_DATABASE_INTERNAL_ERROR]);
}
} else {
$message = $this->getMessage('error', [Request::ERROR_VALIDATE_USER_CREDENTIAL]);
}
return json_encode($message);
}
示例15: actionCreate
/**
* Creates a new User model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new User();
if ($model->load(Yii::$app->request->post())) {
if ($model->validate()) {
$model->salt = Str::random(10);
$model->password = $model->generatePassword($model->password);
if ($model->save(false)) {
Yii::$app->session->setFlash('create_user', '用户添加成功:您可以继续添加新用户,或返回用户列表。');
return $this->redirect(['create']);
}
}
}
return $this->render('create', ['model' => $model]);
}