/** * 添加用户 */ public function actionAdd() { $userForm = new UserForm('add'); if (Yii::app()->request->getIsPostRequest()) { $post = Yii::app()->request->getPost('UserForm'); $userForm->setAttributes($post, false); if ($userForm->validate() && UserModel::instance()->insert($post)) { $this->redirect(array('/user')); } } $this->setTitle('添加用户'); $this->render('add', array('userForm' => $userForm)); }
public function actionRegistration() { $msg = ''; $model = new UserForm('registration'); if (Yii::app()->request->isPostRequest && !empty($_POST['UserForm'])) { $model->setAttributes($_POST['UserForm']); if ($model->validate()) { $user = new UserModel(); $user->setAttributes(['email' => $model->email, 'type' => $model->type, 'password' => UserModel::model()->cryptPass($pass = UserModel::model()->genPassword()), 'hash' => $hash = UserModel::model()->genHash($pass)], FALSE); $user->save(); $info = new UserInfo(); $info->setAttributes(['user_id' => $user->id, 'name' => $model->name, 'surname' => $model->surname], FALSE); $info->save(); Yii::app()->email->send($model->email, 'Регистрация', 'Ваш пароль:' . $pass . '. Для подтверждения учетной записи перейдите по ссылке: ' . $this->createAbsoluteUrl('access/accept', ['hash' => $hash])); $msg = 'Спасибо за регистрацию! проверти почту'; } } $this->render('registration', ['model' => $model, 'msg' => $msg]); }