Exemplo n.º 1
0
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array $credentials
  * @return User
  */
 public function create(array $credentials)
 {
     $credentials = TaketwoUserProvider::initCredentials($credentials);
     $user = new User();
     $user->username = isset($credentials['name']) ? $credentials['name'] : '';
     $user->email = $credentials['type'] == 'email' ? $credentials['identifier'] : '';
     $user->role = User::ROLE_MEMBER;
     $user->save();
     $userAuth = new UserAuth();
     $userAuth->user_id = $user->id;
     $userAuth->type = $credentials['type'];
     $userAuth->identifier = $credentials['identifier'];
     /**
      * crypt password but leave original text for 3rd app
      */
     $userAuth->credential = in_array($credentials['type'], ['email', 'username', 'phone']) ? bcrypt($credentials['credential']) : $credentials['credential'];
     $userAuth->save();
     return $user;
 }
Exemplo n.º 2
0
 /**
  * Validate a user against the given credentials.
  *
  * @param  \Illuminate\Contracts\Auth\Authenticatable $user
  * @param  array $credentials
  * @return bool
  */
 public function validateCredentials(Authenticatable $user, array $credentials)
 {
     $credentials = self::initCredentials($credentials);
     /**
      * 第三方登录不验证credential, 本地用户验证密码
      */
     if (in_array($credentials['type'], ['email', 'username', 'phone'])) {
         $userAuth = UserAuth::where('user_id', $user->id)->where('type', $credentials['type'])->first();
         if ($this->hasher->check($credentials['credential'], $userAuth->credential)) {
             $userAuth->touch();
             return true;
         } else {
             return false;
         }
     } else {
         return true;
     }
 }