Esempio n. 1
0
 /**
  * Creates a new Users model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Users();
     $model->setScenario('register');
     $post = Yii::$app->request->post();
     $formName = basename($model->className());
     if ($model->load($post)) {
         // Default value
         $model->is_super_admin = isset($post[$formName]['is_super_admin']) ? $post[$formName]['is_super_admin'] : 0;
         $model->role = $model->is_super_admin ? Identity::ROLE_SUPERADMIN : 30;
         $model->fecha_conexion = isset($post[$formName]['fecha_conexion']) ? $post[$formName]['fecha_conexion'] : Yii::$app->fn->GetDate('none');
         $model->fecha_modif = isset($post[$formName]['fecha_modif']) ? $post[$formName]['fecha_modif'] : Yii::$app->fn->GetDate('none');
         $model->fecha_registro = isset($post[$formName]['fecha_registro']) ? $post[$formName]['fecha_registro'] : Yii::$app->fn->GetDate();
         $model->id_estado = isset($post[$formName]['id_estado']) ? $post[$formName]['id_estado'] : 1;
         if ($model->validate()) {
             $model->setPassword();
             $model->generateAuthKey();
             if ($model->save()) {
                 return $this->redirect(['view', 'id' => $model->id]);
             }
         }
     }
     // Load empty/error form
     return $this->render('create', ['model' => $model]);
 }
Esempio n. 2
0
 public function registerAction()
 {
     try {
         $form = new \RegisterForm();
         if ($this->request->isPost()) {
             $email = $this->request->getPost('email', 'email');
             $password = $this->request->getPost('password');
             $repeatPassword = $this->request->getPost('repeatPassword');
             $user = new Users();
             $user->setPassword($password, $repeatPassword);
             $user->email = $email;
             $user->created_at = new \Phalcon\Db\RawValue('now()');
             $user->user_name = $this->request->getPost('name', ['string', 'striptags']);
             $user->nickname = $this->request->getPost('nickname', 'string');
             if ($user->save() == false) {
                 foreach ($user->getMessages() as $message) {
                     $this->flash->error((string) $message);
                 }
             } else {
                 $this->tag->setDefault('email', '');
                 $this->tag->setDefault('password', '');
                 $this->auth->login($user->toArray());
                 $user->sendEmailAfterReg();
                 return $this->goToMain();
             }
         }
     } catch (\Exception $e) {
         $this->flash->error($e->getMessage());
     }
     $this->view->form = $form;
 }
Esempio n. 3
0
 public function reg()
 {
     $user = new Users();
     $user->username = $this->username;
     $user->setPassword($this->password);
     $user->generateAuthKey();
     $user->save();
     return $user;
 }
Esempio n. 4
0
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         $adminUserModel = new Users();
         $adminUserModel->setPassword($this->password_hash);
         //print_r($adminUserModel->password_hash);exit();
         $this->password_hash = $adminUserModel->password_hash;
         return true;
     } else {
         return false;
     }
 }
Esempio n. 5
0
 public function signup()
 {
     if ($this->validate()) {
         $users = new Users();
         $users->name = $this->name;
         $users->email = $this->email;
         $users->status = $this->status;
         $users->setPassword($this->password);
         $users->generateAuthKey();
         return $users->save() ? $users : null;
     }
     return null;
 }
Esempio n. 6
0
 public function reg()
 {
     $user = new Users();
     $user->family = $this->family;
     $user->name = $this->name;
     $user->father = $this->father;
     $user->login = $this->login;
     $user->setPassword($this->password);
     $user->email = $this->email;
     $user->phone = $this->phone;
     //$user->generateAuthKey();
     return $user->save() ? $user : null;
 }