예제 #1
0
 public function validateCredentials(UserContract $user, array $credentials)
 {
     $profile = $user instanceof Account ? $user : Account::find($user->getAuthIdentifier());
     if ($profile && $profile->id == $user->getAuthIdentifier()) {
         return static::PAMAuthenticate($profile->username, $credentials['password']);
     }
     return false;
 }
 /**
  * Creates an auth token for user.
  *
  * @param \Illuminate\Contracts\Auth\Authenticatable $user
  * @return \TAppleby\AuthToken\AuthToken|false
  */
 public function create(Authenticatable $user)
 {
     if ($user == null || $user->getAuthIdentifier() == null) {
         return false;
     }
     $token = $this->generateAuthToken();
     $token->setAuthIdentifier($user->getAuthIdentifier());
     $t = new \DateTime();
     $insertData = array_merge($token->toArray(), array('created_at' => $t, 'updated_at' => $t));
     $this->db()->insert($insertData);
     return $token;
 }
 /**
  * @param UserContract $user
  * @return OrganizationMember
  */
 public function getOrganizationMember(UserContract $user)
 {
     $memberClass = $this->getOrgMemberClass();
     $queryMethod = $memberClass->getMethod('query');
     $builder = $queryMethod->invoke(null);
     $member = $builder->where('user_id', '=', $user->getAuthIdentifier())->first();
     return $member;
 }
 /**
  * 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)
 {
     try {
         $result = $this->application->authenticate($credentials['email'], $credentials['password']);
         return $result->account->getHref() == $user->getAuthIdentifier();
     } catch (\Exception $e) {
         return false;
     }
 }
예제 #5
0
 /**
  * Handle user logged in.
  *
  * @param  \Illuminate\Contracts\Auth\Authenticatable  $user
  *
  * @return bool|null
  */
 public function handle(Authenticatable $user)
 {
     $social = $this->session->get('authentication.social.oauth');
     if (is_null($social)) {
         return;
     }
     $model = User::where('provider', '=', $social['provider'])->where('uid', '=', $social['user']->getId())->first();
     if (is_null($model)) {
         return;
     }
     $model->setAttribute('user_id', $user->getAuthIdentifier());
     $model->save();
     return true;
 }
예제 #6
0
 /**
  * Log activity
  *
  * @param string          $action
  * @param string          $description
  * @param \Eloquent       $content
  * @param Authenticatable $user
  * @param Request         $request
  *
  * @return bool
  */
 public function log($action, $description, $content = null, Authenticatable $user = null, Request $request = null)
 {
     $user_id = null;
     $user_type = null;
     $user_name = null;
     if ($user) {
         $user_id = $user->getAuthIdentifier();
         $user_type = get_class($user);
         $user_name = $user->getAuthIdentifierName();
     }
     $content_type = is_object($content) ? get_class($content) : null;
     $content_id = is_object($content) ? $content->id : null;
     $ip_address = $request->ip();
     return (bool) $this->model->create(['action' => $action, 'user_id' => $user_id, 'user_type' => $user_type, 'user_name' => $user_name, 'description' => $description, 'ip_address' => $ip_address, 'content_type' => $content_type, 'content_id' => $content_id]);
 }
예제 #7
0
 /**
  * Log a user into the application.
  *
  * @param \Illuminate\Contracts\Auth\Authenticatable $user
  * @return void
  */
 public function login(AuthenticatableContract $user)
 {
     $claim = new Claim(['sub' => $user->getAuthIdentifier(), 'aud' => get_class($user), 'refresh' => Config::get('jwt.refreshable')]);
     $token = $this->jwtService->getTokenForClaim($claim);
     // If we have an event dispatcher instance set we will fire an event so that
     // any listeners will hook into the authentication events and run actions
     // based on the login and logout events fired from the guard instances.
     $this->fireLoginEvent($user);
     $this->setToken($token);
     $this->setUser($user);
 }
예제 #8
0
 /**
  * Update the "remember me" token for the given user in storage.
  *
  * @param \Illuminate\Contracts\Auth\Authenticatable $user
  * @param string $token
  */
 public function updateRememberToken(Authenticatable $user, $token)
 {
     $this->user->updateRememberToken($user->getAuthIdentifier(), $token);
 }
 /**
  * Update the "remember me" token for the given user in storage.
  *
  * @param  \Illuminate\Contracts\Auth\Authenticatable $user
  * @param  string $token
  * @return void
  */
 public function updateRememberToken(Authenticatable $user, $token)
 {
     $id = $user->getAuthIdentifier();
     if ($this->idShouldBeDecorated()) {
         $id = $this->makeObjectId($user->getAuthIdentifier());
     }
     $this->getCollection()->findAndModify([$this->getIdentificationField() => $id], ['$set' => [$this->getRememberTokenField() => $token]]);
 }
예제 #10
0
 /**
  * Update the "remember me" token for the given user in storage.
  *
  * @param  \Illuminate\Contracts\Auth\Authenticatable  $user
  * @param  string  $token
  * @return void
  */
 public function updateRememberToken(UserContract $user, $token)
 {
     $this->query->filterById($user->getAuthIdentifier())->update(['RememberToken' => $token]);
 }
 /**
  * @param Authenticatable $user
  * @return Volunteer
  */
 public function join(Authenticatable $user)
 {
     $uid = $user->getAuthIdentifier();
     return Volunteer::updateOrCreate(['user_id' => $uid, 'pending' => true, 'accepted' => false]);
 }
 /**
  * Update the "remember me" token for the given user in storage.
  *
  * @param  \Illuminate\Contracts\Auth\Authenticatable  $user
  * @param  string  $token
  * @return void
  */
 public function updateRememberToken(UserContract $user, $token)
 {
     $this->conn->table($this->table)->where('id', $user->getAuthIdentifier())->update(['remember_token' => $token]);
 }
 /**
  * Create the query for the sentiment, modal and user
  *
  * @param string $sentiment
  * @param \Mintbridge\EloquentSentiment\SentimentableInterface $model
  * @param \Illuminate\Contracts\Auth\Authenticatable $user
  */
 private function query($sentiment, SentimentableInterface $model, Authenticatable $user)
 {
     $query = Sentiment::where(Sentiment::ATTR_SENTIMENTABLE_ID, '=', $model->getSentimentableId())->where(Sentiment::ATTR_SENTIMENTABLE_TYPE, '=', $model->getSentimentableType())->where(Sentiment::ATTR_SENTIMENT, '=', $sentiment)->where(Sentiment::ATTR_USER_ID, '=', $user->getAuthIdentifier());
     return $query;
 }
예제 #14
0
 /**
  * Create a new token from the user identifier
  * 
  * @param Authenticatable $user
  * @param Token
  */
 public function refreshToken(Authenticatable $user)
 {
     $claims = ['name' => $user->name, 'email' => $user->email, 'locale' => config('app.locale')];
     return $this->repository->encode($user->getAuthIdentifier(), $claims);
 }
예제 #15
0
 /**
  * @param  Authenticatable  $user
  * @return Token
  */
 public function createTokenForUser(Authenticatable $user)
 {
     $builder = new Builder();
     $id = $user->getAuthIdentifier();
     $builder->setSubject($id);
     if ($user instanceof ProvidesCredentials) {
         $builder = $this->applyClaims($user->getCredentials(), true, $builder);
     }
     $builder->setExpiration($this->getExpirationTimestamp());
     $builder->setId(Str::random());
     return $this->signer->sign($builder)->getToken();
 }
예제 #16
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)
 {
     $username = $user->getAuthIdentifier();
     $credentials = ['username' => $username, 'password' => $credentials['password']];
     return Gatekeeper::authenticate($credentials);
 }
예제 #17
0
 public function addCheck(Authenticatable $user, $ability, $result, $arguments = [])
 {
     $label = $result ? 'success' : 'error';
     $this->addMessage(['ability' => $ability, 'result' => $result, 'user' => $user->getAuthIdentifier(), 'arguments' => $arguments], $label, false);
 }
 /**
  * @param Authenticatable $user
  * @return string|null
  */
 public static function getUserTier(Authenticatable $user)
 {
     $tx = Transaction::where('buyer_id', $user->getAuthIdentifier())->first();
     return isset($tx) ? $tx->product : null;
 }
 /**
  * Update user password if he wants
  *
  * @param \Illuminate\Contracts\Auth\Authenticatable $user
  * @param                                            $plainPass
  */
 public function updatePassword(Authenticatable $user, $plainPass)
 {
     $field = config('auth.password_field', 'password');
     $this->conn->table($this->table)->where('id', $user->getAuthIdentifier())->update([$field => $this->hasher->make($plainPass)]);
 }
예제 #20
0
 /**
  * Log a user into the application.
  *
  * @param  \Illuminate\Contracts\Auth\Authenticatable  $user
  * @return void
  */
 public function login(AuthenticatableContract $user)
 {
     $lifetime = config('session.lifetime');
     $user_id = $user->getAuthIdentifier();
     $expires_on = Carbon::now()->addMinutes($lifetime);
     $this->token = $this->generateAuthorizationToken();
     Cache::put('auth:' . $this->token, compact('user_id', 'expires_on'), $lifetime);
     // If we have an event dispatcher instance set we will fire an event so that
     // any listeners will hook into the authentication events and run actions
     // based on the login and logout events fired from the guard instances.
     $this->fireLoginEvent($user);
     $this->setUser($user);
 }
예제 #21
0
 /**
  * Removes a role from an authenticatable
  * @param Authenticatable $authenticatable
  * @param $role
  * @return mixed
  */
 public function dissociateAuthenticatableOfRole(Authenticatable $authenticatable, $role)
 {
     if ($role instanceof Role) {
         $role = $role->id();
     }
     return AuthenticatableRole::where('authenticatable_id', $authenticatable->getAuthIdentifier())->where('authenticatable_type', get_class($authenticatable))->where('role_id', $role)->delete();
 }
예제 #22
0
 /**
  * Validate a user against the given credentials.
  *
  * @param Authenticatable $user
  * @param  array $credentials
  * @return bool
  */
 public function validateCredentials(Authenticatable $user, array $credentials)
 {
     $userId = $user->getAuthIdentifier();
     return true;
 }
 /**
  * Create the query for the favourite, modal and user
  *
  * @param \Mintbridge\EloquentFavourites\FavouritableInterface $model
  * @param \Illuminate\Contracts\Auth\Authenticatable $user
  */
 private function query(FavouritableInterface $model, Authenticatable $user)
 {
     $query = Favourite::where(Favourite::ATTR_FAVOURITABLE_ID, '=', $model->getFavouritableId())->where(Favourite::ATTR_FAVOURITABLE_TYPE, '=', $model->getFavouritableType())->where(Favourite::ATTR_USER_ID, '=', $user->getAuthIdentifier());
     return $query;
 }
 /**
  * Queue the recaller cookie into the cookie jar.
  *
  * @param  \Illuminate\Contracts\Auth\Authenticatable  $user
  * @return void
  */
 protected function queueRecallerCookie(UserContract $user)
 {
     $value = $user->getAuthIdentifier() . '|' . $user->getRememberToken();
     $this->getCookieJar()->queue($this->createRecaller($value));
 }
예제 #25
0
 /**
  * 寫入登入時間及IP 位址
  *
  * @param  \Illuminate\Contracts\Auth\Authenticatable  $user
  * @return void
  */
 public function updateUserInfo(UserContract $user)
 {
     // 寫入登入IP & 時間
     $this->conn->table($this->table)->where('id', $user->getAuthIdentifier())->update(['ip_address' => Request::ip(), 'last_login' => Carbon::now()]);
     // 寫入可用權限以供nav 選單使用
     $role = $this->conn->table($this->table)->join('roles', 'roles.id', '=', 'users.role_id')->select('roles.permissions')->where('users.id', $user->getAuthIdentifier())->first();
     // 寫入可用權限以供nav 選單使用
     $permissions = json_decode($role->permissions);
     if (in_array('all', $permissions)) {
         $permissions = $this->conn->table('permissions')->select('slug')->where('status', 'true')->get();
     } else {
         $permissions = $this->conn->table('permissions')->select('slug')->whereIn('slug', $permissions)->where('status', 'true')->get();
     }
     // dd($permissions);
     foreach ($permissions as $value) {
         $permission[] = $value->slug;
     }
     // dd($permission);
     session(['permissions' => $permission]);
 }