示例#1
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($domain, $id, UserRequest $request)
 {
     $userService = new userService();
     if ($request->isMethod('POST')) {
         $name = $request->input('name');
         $email = $request->input('email');
         $phone = $request->input('phone');
         $role = $request->input('role');
         $password = $request->input('password');
         $dataUser = ['name' => $name, 'email' => $email, 'phone' => $phone, 'role' => $role];
         if ($password) {
             $password = Hash::make(md5($password));
             array_add($dataUser, 'password', $password);
         }
         $userService->updateItem($id, $dataUser);
     }
     $user = $userService->getUserById($id);
     return view('admin.user.edit', array('item' => $user));
 }
示例#2
0
 /**
  * @param $name
  * @param $email
  * @param $phone
  * @param $password
  * @param $confirmPassword
  * @param string $role
  * @return mixed
  */
 public function signup($name, $email, $phone, $password, $confirmPassword, $role = KACANA_AUTH_BUYER_NAME)
 {
     $userService = new userService();
     $result['ok'] = 0;
     $permissions = [KACANA_AUTH_ADMIN_NAME, KACANA_AUTH_CUS_NAME, KACANA_AUTH_BUYER_NAME];
     if ($this->_user) {
         return false;
     }
     if (!in_array($role, $permissions)) {
         $result['error_code'] = KACANA_AUTH_SIGNUP_ERROR_NOT_EXISTS_PERMISSION;
         $result['error_message'] = 'Không tồn tại role ' . $role . ' trong hệ thống !';
         return $result;
     }
     if ($password != $confirmPassword) {
         $result['error_code'] = KACANA_AUTH_SIGNUP_ERROR_PASSWORD_NOT_MATCH;
         $result['error_message'] = 'password và confirm password không giống nhau !';
         return $result;
     }
     if (!Validator::make(['email' => $email], ['email' => 'required|email'])) {
         $result['error_code'] = KACANA_AUTH_ERROR_BAD_EMAIL;
         $result['error_message'] = 'email không đúng định dạng !';
         return $result;
     }
     if (!Validator::make(['name' => $name], ['name' => 'required|min:2'])) {
         $result['error_code'] = KACANA_AUTH_ERROR_BAD_NAME;
         $result['error_message'] = 'name không đúng định dạng !';
         return $result;
     }
     //Validate phone
     $userModel = new userService();
     $user = $userModel->getUserByEmail($email);
     if ($user && $user->status == KACANA_USER_STATUS_ACTIVE) {
         $result['error_code'] = KACANA_AUTH_SIGNUP_ERROR_EMAIL_EXISTS;
         $result['error_message'] = 'email "' . $email . '" đã tồn tại trong hệ thống !';
         return $result;
     } else {
         if ($user && $user->status == KACANA_USER_STATUS_CREATE_BY_SYSTEM) {
             // user is created when user buy product on system - so update it when they sign up
             $userData = array();
             $userData['name'] = $name;
             $userData['phone'] = $phone;
             $userData['password'] = Hash::make(md5($password));
             $userData['role'] = $role;
             $userData['status'] = KACANA_USER_STATUS_ACTIVE;
             $user = $userService->updateItem($user->id, $userData);
             $result['ok'] = 1;
             $result['data'] = $user;
             return $result;
         } else {
             // create new user
             $userData = array();
             $userData['name'] = $name;
             $userData['email'] = $email;
             $userData['phone'] = $phone;
             $userData['password'] = Hash::make(md5($password));
             $userData['role'] = $role;
             $userData['status'] = KACANA_USER_STATUS_ACTIVE;
             $user = $userService->createUser($userData);
             if ($user) {
                 $result['ok'] = 1;
                 $result['data'] = $user;
                 return $result;
             }
         }
     }
 }