/** * 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()) && $model->validate()) { $model->generatePassword($model->password); $model->created_at = time(); $model->updated_at = time(); $model->status = 1; $model->getAuthKey(); $model->save(); $model->cash_id = md5($model->id); $model->save(); $authManager = \Yii::$app->authManager; $role = $authManager->getRole(User::TYPE_USER); $authManager->assign($role, $model->id); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Signs user up. * * @return User|null the saved model or null if saving fails */ public function signup() { if ($this->validate()) { $user = new User(); $user->username = $this->username; $user->email = $this->email; $user->setPassword($this->password); $user->generateAuthKey(); if ($user->save()) { return $user; } } return null; }