/** * 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; }
/** * Retrieve a user by the given credentials. * * @param array $credentials * @return \Illuminate\Contracts\Auth\Authenticatable|null */ public function retrieveByCredentials(array $credentials) { $credentials = self::initCredentials($credentials); if (!isset($credentials['type']) || !$credentials['type']) { return null; } if (!isset($credentials['identifier']) || !$credentials['identifier']) { return null; } $userAuth = UserAuth::where('type', $credentials['type'])->where('identifier', $credentials['identifier'])->first(); if (!$userAuth) { return null; } return User::find($userAuth->user_id); }