示例#1
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]);
     }
 }
 /**
  * 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]);
     }
 }
 /**
  * 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];
     }
 }
 /**
  * 系统初始化,创建管理员
  * 
  * */
 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();
 }