示例#1
0
 /**
  * Create a new user
  *
  * <b>Request Type</b>: POST<br/><br/>
  * <b>Request Endpoint</b>:http://{server-domain}/management/user<br/><br/>
  * <b>Content-type</b>: application/json<br/><br/>
  * <b>Summary</b>: This api is used for billing account to create a new user
  * <br/><br/>
  *
  * <b>Request Params</b>:<br/>
  *     email: string, the user email, required<br/>
  *     role: string, the user role, required<br/>
  *     <br/><br/>
  *
  * <b>Response Params:</b><br/>
  *     ack: integer, mark the create result, 0 means create successfully, 1 means create fail<br/>
  *     data: array, json array to describe the user created<br/>
  *     <br/><br/>
  *
  * <b>Request Example:</b><br/>
  * <pre>
  * {
  *     "email" : "*****@*****.**",
  *     "role" : "admin"
  * }
  * </pre>
  * <br/><br/>
  *
  * <b>Response Example</b>:<br/>
  * <pre>
  * {
  *    'ack' : 1,
  *    'data': {"msg": "您当前已成功发送验证邮件到sarazhang@augmentum.com.cn邮箱中", "user": {name:"Devin Jin", avatar:"path/to/avatar", email:"*****@*****.**", isActivated:false}}
  * }
  * </pre>
  */
 public function actionCreate()
 {
     $params = $this->getParams();
     if (empty($params['email'])) {
         throw new InvalidParameterException(['email' => Yii::t('common', 'email_is_required')]);
     }
     $params['email'] = mb_strtolower($params['email']);
     if (!StringUtil::isEmail($params['email'])) {
         throw new InvalidParameterException(['email' => Yii::t('helpDesk', 'email_format_wrong')]);
     }
     $user = User::getByEmail($params['email']);
     if (!empty($user)) {
         throw new InvalidParameterException(['email' => Yii::t('helpDesk', 'email_has_used')]);
     }
     $user = new User();
     $user->email = $params['email'];
     $user->role = $params['role'];
     $user->avatar = Yii::$app->params['defaultAvatar'];
     $user->isActivated = User::NOT_ACTIVATED;
     $user->accountId = $this->getAccountId();
     if ($user->save()) {
         $currentUser = $this->getUser();
         $link = Yii::$app->request->hostInfo . '/site/invite/code?type=2';
         //type=2 means invite user account
         $result = EmailUtil::sendInviteEmail($user, $currentUser->name, $link, self::SUBJECT);
         if ($result) {
             return ['user' => $user];
         } else {
             throw new ServerErrorHttpException("validation save fail");
         }
     }
     throw new ServerErrorHttpException("create user fail");
 }
示例#2
0
 public function save($runValidation = true, $attributeNames = null)
 {
     if ($this->new_password) {
         $this->setPassword($this->new_password);
     }
     return parent::save($runValidation, $attributeNames);
 }
 /**
  * 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(['scenario' => 'signup']);
     $model1 = new AmgenContactListvalidate();
     if ($model->load(Yii::$app->request->post()) && $model1->load(Yii::$app->request->post()) && $model->validate() && $model1->validate()) {
         $fname = $_POST['AmgenContactListvalidate']['first_name'];
         $lname = $_POST['AmgenContactListvalidate']['last_name'];
         $model1->first_name = $fname;
         $model1->last_name = $lname;
         $model1->Title = $_POST['AmgenContactListvalidate']['Title'];
         $model1->function_Id = $_POST['AmgenContactListvalidate']['function_Id'];
         $model1->group_Id = $_POST['AmgenContactListvalidate']['group_Id'];
         $model1->Phone = $_POST['AmgenContactListvalidate']['Phone'];
         $model1->speciality = $_POST['AmgenContactListvalidate']['speciality'];
         $fullname = $fname . " " . $lname;
         $model1->Name = $fullname;
         if ($model1->save()) {
             $id = $model1->id;
             $password = $_POST['User']['password_hash'];
             $hash = Yii::$app->getSecurity()->generatePasswordHash($password);
             $model->password_hash = $hash;
             //generating password hash
             $model->attendee_id = $id;
             $model->first_name = $fname;
             $model->last_name = $lname;
             $model->save();
             Yii::$app->session->setFlash('success', 'User Sucessfully Created');
             return $this->redirect(['view', 'id' => $model->id]);
         }
     } else {
         return $this->render('create', ['model' => $model, 'model1' => $model1]);
     }
 }
示例#4
0
 public function actionCreate()
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     $model = new User();
     $model->username = Yii::$app->request->post('name');
     $model->email = Yii::$app->request->post('email');
     $model->pass1 = Yii::$app->request->post('pass1');
     $model->pass2 = Yii::$app->request->post('pass2');
     $model->role = 1;
     $model->created_at = time();
     $model->auth_key = Yii::$app->security->generateRandomString();
     $user = User::find()->where(['username' => $model->username])->one();
     $mail = User::find()->where(['email' => $model->email])->one();
     if (!$model->pass1 === $model->pass2) {
         return ['status' => 'error', 'error' => array('password' => 'Passwords must be identical.')];
     } elseif ($user) {
         return ['status' => 'error', 'error' => array('login' => 'User with login ' . $model->username . ' already registered.')];
     } elseif ($mail) {
         return ['status' => 'error', 'error' => array('email' => 'User with login ' . $model->email . ' already registered.')];
     } elseif ($model->save()) {
         $model->role == 2 ? Yii::$app->authManager->assign(Yii::$app->authManager->getRole('admin'), $model->id) : Yii::$app->authManager->assign(Yii::$app->authManager->getRole('user'), $model->id);
         return ['status' => 'success', 'data' => $model];
     } else {
         return ['status' => 'error', 'data' => $model];
     }
 }
示例#5
0
 /**
  * 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->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
示例#6
0
 /**
  * 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(['scenario' => 'admin-create']);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         Yii::$app->authManager->assign(Yii::$app->authManager->getRole($model->role), $model->id);
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
示例#7
0
 public function reg()
 {
     $user = new User();
     $user->username = $this->username;
     $user->email = $this->email;
     $user->status = $this->status;
     $user->setPassword($this->password);
     $user->generateAuthKey();
     return $user->save() ? $user : null;
 }
示例#8
0
 /**
  * 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->save()) {
         // Yii::$app->Controllers->activity_user("[CREATE COS]");
         Yii::$app->Controllers->historyUserWithData($model);
         echo 1;
     } else {
         return $this->renderAjax('create', ['model' => $model]);
     }
 }
示例#9
0
 /**
  * Creates a new User model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     //if(!Yii::$app->user->can('createUser')) throw new ForbiddenHttpException(Yii::t('app', 'No Auth'));
     $model = new User(['scenario' => 'admin-create']);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         //Yii::$app->authManager->assign(Yii::$app->authManager->getRole($model->role), $model->id);
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
示例#10
0
 /**
  * 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->auth_key = Yii::$app->security->generateRandomString();
         $model->password_hash = Yii::$app->security->generatePasswordHash($model->newpass);
         $model->password_reset_token = NULL;
         $model->save();
         $this->actionApprole($model->id, 'user');
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'admin' => true]);
     }
 }
示例#11
0
 /**
  * 创建用户
  *
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new User();
     if ($model->load(Yii::$app->request->post())) {
         $model->setPassword('123456');
         $model->generateAuthKey();
         //$model->signup();
         $ret = $model->save();
         if ($ret) {
             return $this->redirect(['index']);
         }
     }
     return $this->render('create', ['model' => $model]);
 }
示例#12
0
 /**
  * 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;
 }
 /**
  * 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 (Yii::$app->request->isPost) {
         $model->load(Yii::$app->request->post());
         if ($model->save()) {
             $userdata = new WooUserData();
             $userdata->user_id = $model->id;
             $userdata->user_name = "Unset";
             $userdata->user_lastname = "Unset";
             $model->link("woouserdata", $userdata);
             return $this->redirect(['view', 'id' => $model->id]);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
示例#14
0
文件: User.php 项目: quyettvq/luspel
 /**
  * function ::create ($data)
  */
 public static function create($data)
 {
     $now = strtotime('now');
     $username = Yii::$app->user->identity->username;
     $model = new User();
     if ($model->load($data)) {
         if ($log = new UserLog()) {
             $log->username = $username;
             $log->action = "Create";
             $log->object_class = "User";
             $log->created_at = $now;
             $log->is_success = 0;
             $log->save();
         }
         $model->created_at = $now;
         $model->dob = strtotime($model->dob);
         do {
             $path = FileUtils::generatePath($now);
         } while (file_exists(Yii::$app->params['images_folder'] . $path));
         $model->image_path = $path;
         $targetFolder = Yii::$app->params['images_folder'] . $model->image_path;
         $targetUrl = Yii::$app->params['images_url'] . $model->image_path;
         if (!empty($data['user-image'])) {
             $copyResult = FileUtils::copyImage(['imageName' => $model->image, 'fromFolder' => Yii::$app->params['uploads_folder'], 'toFolder' => $targetFolder, 'resize' => [[120, 120], [200, 200]], 'resizeType' => 2, 'removeInputImage' => true]);
             if ($copyResult['success']) {
                 $model->image = $copyResult['imageName'];
             }
         }
         // User class
         $model->generateAuthKey();
         $model->setPassword($model->password);
         if ($model->save()) {
             if ($log) {
                 $log->object_pk = $model->id;
                 $log->is_success = 1;
                 $log->save();
             }
             return $model;
         }
         $model->getErrors();
         return $model;
     }
     return false;
 }
示例#15
0
 /**
  * Creates a new User model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     if (Yii::$app->user->can('createUser')) {
         $model = new User();
         if ($model->load(Yii::$app->request->post())) {
             $lastInsertID = $model->getPrimaryKey();
             $model->id = $lastInsertID;
             $model->password_hash = Yii::$app->security->generatePasswordHash($_POST['User']['password_hash']);
             $model->created_at = time();
             $model->updated_at = time();
             $model->save(false);
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     } else {
         throw new ForbiddenHttpException();
     }
 }
示例#16
0
 /**
  * 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();
     $model->scenario = 'create';
     if ($model->load(Yii::$app->request->post())) {
         $image = $model->uploadImage();
         if ($model->save()) {
             // upload only if valid uploaded file instance found
             if ($image !== false) {
                 $path = $model->getImageFile();
                 $image->saveAs($path);
             }
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
示例#17
0
 public function addCustomer($nickName, $password, $mobile, $realName)
 {
     //用户名已存在
     if ($this->findUserByNickName($nickName)) {
         return false;
     }
     $user = new User();
     $user->nickName = $nickName;
     $user->password = md5($password);
     $user->mobile = $mobile;
     $user->realName = $realName;
     $user->registerTime = date('Y-m-d H:i:s', time());
     $user->lastLoginTime = date('Y-m-d H:i:s', time());
     $user->salt = 'shgyx';
     $user->addTime = date('Y-m-d H:i:s', time());
     $user->addUser = \Yii::$app->session->get(Variable::$session_userId_str);
     if ($user->save() > 0) {
         return true;
     }
     return false;
 }
示例#18
0
 public function actionCreate()
 {
     $error = '';
     $model = new User();
     $data['_csrf'] = Yii::$app->request->post('_csrf', '');
     $data['User'] = Yii::$app->request->post();
     if (isset($data['User']['submit'])) {
         $error .= empty($data['User']['username']) ? '<p> - Username không được bỏ trống </p>' : '';
         $error .= empty($data['User']['full_name']) ? '<p> - Full_name không được bỏ trống </p>' : '';
         $error .= empty($data['User']['password']) ? '<p> - Password không được bỏ trống </p>' : '';
         $error .= empty($data['User']['re-password']) ? '<p> - Re-password không được bỏ trống </p>' : '';
         $error .= empty($data['User']['email']) ? '<p> - Email không được bỏ trống </p>' : '';
         if (!empty($data['User']['password']) && !empty($data['User']['re-password'])) {
             $error .= $data['User']['password'] != $data['User']['re-password'] ? '<p> - Password nhập lại không chính xác' : '';
         }
         $checkUsername = $model->findByUsername($data['User']['username']);
         $checkEmail = $model->findByEmail($data['User']['email']);
         $error .= !empty($checkUsername) ? '<p> - Username đã tồn tại </p>' : '';
         $error .= !empty($checkEmail) ? '<p> - Email đã được sử dụng </p>' : '';
         $data['User']['create_date'] = time();
         $data['User']['user_create'] = \Yii::$app->user->id;
         $data['User']['password'] = md5(md5($data['User']['password']) . 'cinefun2015');
     }
     if (empty($error) && $model->load($data) && $model->save()) {
         $user = $model->findByUsername($data['User']['username']);
         $id = $user->id;
         $auth = new AuthAssignment();
         $dataAuth['_csrf'] = $data['_csrf'];
         $dataAuth['AuthAssignment']['item_name'] = $data['User']['group'];
         $dataAuth['AuthAssignment']['user_id'] = $id;
         $dataAuth['AuthAssignment']['created_at'] = time();
         $auth->load($dataAuth);
         $auth->save();
         return $this->redirect(['index']);
     } else {
         $group = $model->getGroup();
         return $this->render('create', ['group' => $group, 'error' => $error]);
     }
 }
示例#19
0
 /**
  * create a user by email(generate-by-email)
  */
 public function actionGenerateByEmail($email)
 {
     $email = mb_strtolower($email);
     $user = User::getByEmail($email);
     if (!empty($user)) {
         echo 'email is used' . PHP_EOL;
         return;
     }
     $name = Yii::$app->params['defaultName'];
     $accountId = Account::create('', '', $name);
     $attributes = ['status' => Account::STATUS_ACTIVATED, 'availableExtMods' => Yii::$app->params['extMods'], 'serviceStartAt' => new \MongoDate()];
     Account::updateAll($attributes, ['_id' => $accountId]);
     $salt = StringUtil::rndString(6);
     $password = User::encryptPassword(md5(Yii::$app->params['defaultPwd']), $salt);
     $user = new User();
     $user->email = $email;
     $user->accountId = $accountId;
     $user->name = $name;
     $user->role = User::ROLE_ADMIN;
     $user->isActivated = User::ACTIVATED;
     $user->avatar = Yii::$app->params['defaultAvatar'];
     $user->language = Yii::$app->params['defaultLanguage'];
     $user->salt = $salt;
     $user->password = $password;
     if (!$user->save()) {
         Account::deleteAll(['_id' => $accountId]);
         SensitiveOperation::deleteAll(['accountId' => $accountId]);
         MessageTemplate::deleteAll(['accountId' => $accountId]);
         echo 'create account fail' . PHP_EOL;
     } else {
         echo 'create account successfully' . PHP_EOL;
     }
 }
示例#20
0
 /**
  * Register billing account
  *
  * <b>Request Type</b>: POST<br/><br/>
  * <b>Request Endpoint</b>:http://{server-domain}/site/register<br/><br/>
  * <b>Content-type</b>: application/json<br/><br/>
  * <b>Summary</b>: This api is used for registering user.
  * <br/><br/>
  *
  * <b>Request Params</b>:<br/>
  *     name: string, the user name<br/>
  *     email: string, the user email<br/>
  *     password: string, the user password<br/>
  *     <br/><br/>
  *
  * <b>Response Params:</b><br/>
  *     ack: integer, mark the create result, 1 means create successfully, 0 means create fail<br/>
  *     message: string, if create fail, it contains the error message<br/>
  *     data: array, json array to describe all users detail information<br/>
  *     <br/><br/>
  *
  * <b>Request Example:</b><br/>
  * <pre>
  * {
  *     "name" : "harrysun",
  *     "email" : "*****@*****.**",
  *     "password" : "abc123_"
  * }
  * </pre>
  * <br/><br/>
  *
  * <b>Response Example</b>:<br/>
  * <pre>
  * {
  *    'ack' : 1,
  *    'message': ''
  * }
  * </pre>
  */
 public function actionRegister()
 {
     $data = $this->getParams();
     $account = new Account();
     $account->save();
     $user = new User();
     $user->name = $data['name'];
     $user->email = $data['email'];
     $user->salt = StringUtil::rndString(6);
     $user->password = User::encryptPassword($data['password'], $user->salt);
     $user->accountId = $account->_id;
     $user->role = User::ROLE_ADMIN;
     $user->isActivated = User::NOT_ACTIVATED;
     $user->avatar = Yii::$app->params['defaultAvatar'];
     $user->language = 'zh_cn';
     if ($user->validate()) {
         // all inputs are valid
         if ($user->save()) {
             $validation = new Validation();
             $validation->userId = $user->_id;
             $validation->code = StringUtil::uuid();
             $validation->expire = new \MongoDate(strtotime('+1 day'));
             if ($validation->save()) {
                 $mail = Yii::$app->mail;
                 $host = Yii::$app->request->hostInfo;
                 $vars = ['name' => $user->name, 'link' => $host . '/api/old-site/activate?code=' . $validation->code, 'host' => $host];
                 $mail->setView('//mail/register', $vars, '//layouts/email');
                 $mail->sendMail($user->email, '欢迎注册WeMarketing');
                 return ["ack" => 1, "message" => 'Register success.'];
             } else {
                 return ["ack" => 0, "message" => 'Validation save fail.'];
             }
         } else {
             return ["ack" => 0, "message" => 'Register user fail.'];
         }
     } else {
         // validation failed: $errors is an array containing error messages
         $errors = $user->errors;
         //revert the accout data
         Account::deleteAll(['_id' => $account->_id]);
         return ["ack" => 0, "message" => $errors];
     }
 }
示例#21
0
 /**
  * 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()) {
         // print_r($_POST);
         // die();
         $pass = Yii::$app->security->generatePasswordHash($_POST['User']['password']);
         $model->password_hash = $pass;
         $content = '
                 <center><img src="http://i.imgur.com/rkxzCKf.png"/></center><br/>
                 <h4 align="center">Sekolah Tinggi Terpadu Nurul Fikri ' . date('Y') . '</h4>
                 <hr/>
                 <p>Yth ' . $model->username . ',<br/>  
                 Dengan ini kami sampaikan password telah direset  sebagai berikut:<br/> 
                 Username : '******' <br/>
                 Password :<b>' . $_POST['User']['password'] . '</b><br/>
                 Mohon lakukan penggantian password Anda setelah melakukan login. <hr/>
                 <h5 align="center">Developer By Hendra Aditya Wijaya Mentor Ilham Malik Ibrahim' . date('Y') . '</h5><br/>';
         Yii::$app->mailer->compose("@common/mail/layouts/html", ["content" => $content])->setTo($_POST['User']['email'])->setFrom([$_POST['User']['email'] => 'Aplikasi Simpel Bapeten'])->setSubject('Ubah Kata Sandi')->setTextBody($_POST['User']['password'])->send();
         $model->save();
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model]);
     }
 }
示例#22
0
 public function actionGenerate()
 {
     $model = Alumni::find()->asArray()->all();
     $counter = 0;
     foreach ($model as $rA) {
         $course_name = $rA['e_program'];
         $ei_graduation_year = $rA['e_tahun_tamat'];
         $pi_name = $rA['e_nama'];
         $pi_ic_or_passport = $rA['e_kp'];
         $pi_gender = $rA['e_jantina'];
         $pi_address = $rA['e_alamat'];
         $pi_zipcode = $rA['e_poskod'];
         $pi_address_permanent = $rA['e_alamat_tetap'];
         $pi_zipcode_permanent = $rA['e_poskod_tetap'];
         $pi_phone_home = $rA['e_tel_rumah'];
         $pi_hp = $rA['e_tel_hp'];
         $pi_email_1 = $rA['e_emel1'];
         $pi_email_2 = $rA['e_emel2'];
         $AlumniCur = User::find()->select(['user.id', 'user.pi_id', 'user_education.*', 'course.*'])->joinWith(['pi', 'userEducations', 'educationInformation', 'course'])->where(['pi_ic_or_passport' => $pi_ic_or_passport])->asArray()->all();
         if (sizeof($AlumniCur) > 0 and $AlumniCur[0]['course']['course_name'] == $course_name) {
             continue;
         }
         $mdlCourse = InstitutionCourse::find()->joinWith(['course'])->where(['course_name' => $course_name])->asArray()->all();
         $aCourse = sizeof($mdlCourse) > 0 ? $mdlCourse[0] : [];
         if (sizeof($aCourse) > 0) {
             $course_id = $aCourse['course_id'];
             $inst_id = $aCourse['inst_id'];
             $aLevel_code = explode(" ", $course_name);
             $el_code = $aLevel_code[0];
             //check if education information already registered
             $mdlEduInfo = EducationInformation::find()->where(['course_id' => $course_id, 'inst_id' => $inst_id, 'ei_graduation_year' => $ei_graduation_year])->asArray()->all();
             $mdlEducationLevel = EducationLevel::find()->where(['el_name' => $el_code])->asArray()->all();
             $aEL = sizeof($mdlEducationLevel) > 0 ? $mdlEducationLevel[0] : [];
             $el_id = $aEL['el_id'];
         }
         $pi = new PersonalInformation();
         $usr = new User();
         //let's insert the data to database
         if (sizeof($AlumniCur) == 0) {
             $pi->pi_name = $pi_name;
             $pi->pi_ic_or_passport = $pi_ic_or_passport;
             $pi->pi_gender = $pi_gender;
             $pi->pi_address = $pi_address;
             $pi->pi_zipcode = $pi_zipcode;
             $pi->pi_address_permanent = $pi_address_permanent;
             $pi->pi_zipcode_permanent = $pi_zipcode_permanent;
             $pi->pi_phone_home = $pi_phone_home;
             $pi->pi_hp = $pi_hp;
             $pi->pi_email_1 = $pi_email_1;
             $pi->pi_email_2 = $pi_email_2;
             $pi->save();
             $cost = 10;
             $salt = strtr(base64_encode(mcrypt_create_iv(16, MCRYPT_DEV_URANDOM)), '+', '.');
             $salt = sprintf("\$2a\$%02d\$", $cost) . $salt;
             $hash = crypt('demo', $salt);
             $usr->pi_id = $pi->pi_id;
             $usr->username = $pi_ic_or_passport;
             $usr->auth_key = 'vBZS7KGrvXesyOkgQhGYCY5KCZi6st5g';
             $usr->password_hash = $hash;
             $usr->created_at = time();
             $usr->updated_at = time();
             $usr->save();
         } else {
             $usr->id = $AlumniCur[0]['id'];
         }
         if (sizeof($aCourse) == 0) {
             continue;
         }
         $ei = new EducationInformation();
         if (sizeof($mdlEduInfo) == 0) {
             $ei->inst_id = $inst_id;
             $ei->course_id = $course_id;
             $ei->el_id = $el_id;
             $ei->ei_graduation_year = $ei_graduation_year;
             $ei->save();
         } else {
             $ei->ei_id = $mdlEduInfo[0]['ei_id'];
         }
         $ue = new UserEducation();
         $ue->id = $usr->id;
         $ue->ei_id = $ei->ei_id;
         $ue->save();
         //dpo: break to test one data only
         //break;
     }
 }
示例#23
0
 /**
  * Register billing account
  *
  * <b>Request Type</b>: POST<br/><br/>
  * <b>Request Endpoint</b>:http://{server-domain}/api/site/register<br/><br/>
  * <b>Content-type</b>: application/json<br/><br/>
  * <b>Summary</b>: This api is used for registering user.
  * <br/><br/>
  *
  * <b>Request Params</b>:<br/>
  *     name: string, the user name<br/>
  *     email: string, the user email<br/>
  *     password: string, the user password<br/>
  *     <br/><br/>
  *
  * <b>Response Params:</b><br/>
  *     ack: integer, mark the create result, 1 means create successfully, 0 means create fail<br/>
  *     message: string, if create fail, it contains the error message<br/>
  *     data: array, json array to describe all users detail information<br/>
  *     <br/><br/>
  *
  * <b>Request Example:</b><br/>
  * <pre>
  * {
  *     "name" : "harrysun",
  *     "email" : "*****@*****.**",
  *     "company" : "Augmentum",
  *     "phone" : "13027785897",
  *     "captcha" : "123456"
  * }
  * </pre>
  * <br/><br/>
  *
  * <b>Response Example</b>:<br/>
  * <pre>
  * {
  *    'message': 'Register success.'
  * }
  * </pre>
  */
 public function actionRegister()
 {
     //set language zh_cn when sign up
     \Yii::$app->language = LanguageUtil::LANGUAGE_ZH;
     $data = $this->getParams();
     if (empty($data['name']) || empty($data['email']) || empty($data['company']) || empty($data['phone']) || empty($data['captcha']) || empty($data['position'])) {
         throw new BadRequestHttpException('missing param');
     }
     $phone = $data['phone'];
     $this->attachBehavior('CaptchaBehavior', new CaptchaBehavior());
     $this->checkCaptcha($phone, $data['captcha']);
     $email = mb_strtolower($data['email']);
     $user = User::getByEmail($email);
     if (!empty($user)) {
         //check if user active fail, send email again
         if (!$user->isActivated) {
             $validation = Validation::getByUserId($user->_id);
             return $this->_sendRegistEmail($user->_id, $data, $validation);
         } else {
             throw new InvalidParameterException(['email' => \Yii::t('common', 'unique_feild_email')]);
         }
     }
     $accountId = Account::create($data['company'], $phone, $data['name']);
     $user = new User();
     $user->email = $email;
     $user->position = $data['position'];
     $user->accountId = $accountId;
     $user->role = User::ROLE_ADMIN;
     $user->isActivated = User::NOT_ACTIVATED;
     $user->avatar = Yii::$app->params['defaultAvatar'];
     $user->language = LanguageUtil::DEFAULT_LANGUAGE;
     if ($user->save()) {
         return $this->_sendRegistEmail($user->_id, $data);
     } else {
         Account::deleteAll(['_id' => $accountId]);
         if ($user->getErrors('email')) {
             throw new InvalidParameterException(['email' => \Yii::t('common', 'unique_feild_email')]);
         }
         throw new ServerErrorHttpException('regist fail');
     }
 }
示例#24
0
 /**
  * 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();
     $pi = new PersonalInformation();
     if ($pi->load(Yii::$app->request->post())) {
         /*print_r($this->pi_name);
           die();*/
         /*$pi = new PersonalInformation();
           $pi->load(Yii::$app->request->post());*/
         $pi->pi_name = $pi->pi_name;
         $pi->save();
         if ($pi->save() == 1) {
             // this is inserted user id
             //$model = new User();
             $model->load(Yii::$app->request->post());
             /*print_r($model);
               //print_r($pi);
               die();*/
             $userID = $pi->pi_id;
             $model->pi_id = $userID;
             $model->username = $model->username;
             $model->status = $model->status;
             $model->online_status = "0";
             $model->created_at = time();
             $model->updated_at = time();
             $model->auth_key = "vBZS7KGrvXesyOkgQhGYCY5KCZi6st5g";
             $model->password_hash = "\$2y\$13\$4cRqqw0nmEj5.NJRcJYaE.YUSh9DJaQsSpLM3OCicXckrCPoAgWYC";
             $model->save();
             /*print_r($model->getErrors());
               die();*/
         }
         return $this->redirect(['index', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * 系统初始化,创建管理员
  * 
  * */
 public function actionCreateAdmin()
 {
     $params = Yii::$app->request->post("CreateUser");
     $user_name = empty($params['username']) ? '' : $params['username'];
     $pwd = empty($params['password']) ? '' : $params['password'];
     $confirm_pwd = empty($params['confirmPassword']) ? '' : $params['confirmPassword'];
     $email = empty($params['email']) ? '' : $params['email'];
     $res = new Response();
     if ($pwd != $confirm_pwd) {
         $res->success = false;
         $res->message = '两次密码输入不一样';
     }
     $is_user = User::find()->all();
     //判断是否创建过管理员帐号
     if (!empty($is_user)) {
         $res->success = false;
         $res->message = '该系统已经创建过测试帐号';
     }
     $user = new User();
     $user->username = $user_name;
     $user->password_hash = $pwd;
     $user->email = $email;
     if ($user->validate() && $user->save()) {
         $res->success = true;
         $res->message = '创建系统管理员成功';
         //为超级管理员授权
         $auth = Yii::$app->authManager;
         // //创建管理员
         // $role = $auth->createRole('admin');
         // $role->description = '系统管理员';
         // $auth->add($role);
         // $auth->addChild($role, $privileges_manage);
         // $role = $auth->getRole( 'admin' );
         // $auth->assign($role, $user_id);
         if (!$auth->assign($role, $user->user_id)) {
             $res->success = false;
             $res->message = '创建系统管理员权限失败';
         }
     } else {
         $res->success = false;
         $res->message = '创建系统管理员失败';
     }
     $res->to_json();
 }