/** * Creates a new Admin model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Admin(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Admin model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Admin(); if ($model->load(Yii::$app->request->post()) && $model->setPassword($model->new_password) && $model->save(true, array('id', 'name', 'username', 'email', 'password_hash', 'english_name', 'role', 'status', 'created_at', 'updated_at'))) { return $this->redirect(['user/index']); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Admin model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Admin(); if (Yii::$app->request->isPost) { $adminInfo = Yii::$app->request->post(); $adminInfo['Admin']['group_id'] = implode(',', $adminInfo['Admin']['group_id']); if ($model->load($adminInfo) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Admin model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Admin(); $model->update = false; if ($model->load(Yii::$app->request->post())) { $model->password = md5($model->password); $model->repeatpassword = md5($model->repeatpassword); if ($model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model]); } } else { return $this->render('create', ['model' => $model]); } }
public function actionLogin() { $model = new Admin(); if ($model->load(\Yii::$app->request->post())) { $request = \Yii::$app->request->post('Admin'); $username = $request['username']; $password = $request['password']; $checkLogin = $model->checkLogin($username, $password); if ($checkLogin) { \Yii::$app->session->set('admin', $username); $this->layout = 'admin'; return $this->redirect(['admin/index']); } else { $this->layout = 'admin'; return $this->render('login', ['model' => $model, 'error' => 'Tên đăng nhập hoặc mật khẩu không đúng']); } } else { $this->layout = 'admin'; return $this->render('login', ['model' => $model]); } }
/** * Creates a new Admin model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Admin(); if ($model->load(Yii::$app->request->post())) { if ($model->save()) { $signUp = new \frontend\models\SignupForm(); $signUp->username = $model->username; $signUp->email = $model->username . '@gmail.com'; $signUp->password = $model->password; $signUp->level = 'admin'; if ($signUp->signup()) { Yii::$app->session->setFlash('success', 'Simpan Berhasil'); } else { Yii::$app->session->setFlash('warning', 'Simpan gagal'); } } else { Yii::$app->session->setFlash('warning', 'Failed'); } return $this->redirect(['index']); } else { return $this->render('create', ['model' => $model]); } }