Ejemplo n.º 1
0
 public function registerRepos($username, $email, $password)
 {
     $user = new User();
     $user->name = $username;
     $user->email = $email;
     $user->password = Hash::make($password);
     $user->save();
 }
Ejemplo n.º 2
0
 /**
  * Создать
  */
 public function actionCreate()
 {
     $model = new User();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return Yii::$app->getResponse()->redirect(['/admin/user/update', 'id' => $model->id]);
     }
     return $this->render('create', ['model' => $model]);
 }
 public function up()
 {
     $auth = Yii::$app->authManager;
     $superAdminPermission = $auth->createPermission('*/*/*');
     $superAdminPermission->description = 'Суперадминистративные права';
     $auth->add($superAdminPermission);
     $superadmin = $auth->createRole('superadmin');
     $superadmin->description = 'Суперадминистраторы';
     $auth->add($superadmin);
     $auth->addChild($superadmin, $superAdminPermission);
     $user = new User();
     $user->attributes = ['is_active' => 1, 'email' => '*****@*****.**', 'new_password' => 'test', 'roles' => ['superadmin']];
     $user->save();
 }
Ejemplo n.º 4
0
 /**
  * @新增企业号 数据入库
  */
 public function registerEnterprise($data = null, $Ip = null)
 {
     $data['user_id'] = 0;
     $data['user_type'] = count($data['user_type']) > 1 ? 4 : $data['user_type'][0];
     $data['user_addtime'] = time();
     $data['user_lastlogin'] = time();
     $data['user_lastip'] = $Ip;
     $data['user_status'] = 1;
     $model = new User();
     $model->attributes = $data;
     if (!is_null($this->onlyPhone($data['user_phone']))) {
         return $this->result(3, '手机号已存在');
     }
     if (!is_null($this->onlyEnterprise($data['mer_name']))) {
         return $this->result(4, '企业名称已存在');
     }
     if ($model->validate()) {
         $transaction = \Yii::$app->db->beginTransaction();
         try {
             $model->setAttributes($data);
             $model->user_password = md5($data['user_password']);
             $model->save(false);
             $user_id = $model->attributes['user_id'];
             $mer = new MerBase();
             $mer->mer_id = $user_id;
             $mer->mer_name = $data['mer_name'];
             $mer->mer_phone = $data['user_phone'];
             $mer->register_time = time();
             $mer->save(false);
             $transaction->commit();
             //提交事务会真正的执行数据库操作
             return $this->result(1, '注册成功');
         } catch (Exception $e) {
             $transaction->rollback();
             //如果操作失败, 数据回滚
             return $this->result(2, '注册失败');
         }
     } else {
         // 验证失败:$errors 是一个包含错误信息的数组
         $errors = $model->errors;
         if (count($errors) > 1) {
             return $this->result(5, '非法注册,请通过正确途径注册');
         } else {
             $val = array_values($errors);
             return $this->result(6, $val[0][0]);
         }
     }
 }