Inheritance: extends ModelBase
Beispiel #1
0
 public function registerAction()
 {
     if ($this->request->isAjax()) {
         $user_name = $this->request->get('user_name', 'account');
         $email = $this->request->get('email', 'email');
         $password = $this->request->get('password', 'password');
         $code = $this->request->get('code');
         $this->captcha->verify($code);
         if (Admin::exists(['admin_name' => $user_name])) {
             return $this->response->setJsonContent(['code' => __LINE__, 'error' => 'account already exists.']);
         }
         if (AdminDetail::exists(['email' => $email])) {
             return $this->response->setJsonContent(['code' => __LINE__, 'error' => 'email already exists.']);
         }
         $current_time = time();
         $admin = new Admin();
         $admin->admin_name = $user_name;
         $admin->salt = $this->password->salt();
         $admin->password = $this->password->hash($password, $admin->salt);
         $admin->created_time = $current_time;
         $admin->updated_time = $current_time;
         $admin->create();
         $adminDetail = new AdminDetail();
         $adminDetail->admin_id = $admin->admin_id;
         $adminDetail->admin_name = $admin->admin_name;
         $adminDetail->email = $email;
         $adminDetail->created_time = $current_time;
         $adminDetail->updated_time = $current_time;
         $adminDetail->create();
         return $this->response->setJsonContent(['code' => 0, 'error' => '']);
     }
 }