Beispiel #1
0
 /**
  * Make token for the given user
  *
  * @param \Tajrish\Models\User $user
  * @param                      $token
  * @param \Carbon\Carbon|null  $expiresAt
  * @return \Illuminate\Database\Eloquent\Model
  */
 public function makeUniqueTokenForUser(User $user, $token, Carbon $expiresAt = null)
 {
     if ($expiresAt && $expiresAt->isPast()) {
         throw new \InvalidArgumentException('Token expiration can not be at past.');
     }
     $expiresAt = $expiresAt ?: Carbon::now()->addMinutes(config('tajrish.expires_at_minutes', 24 * 60 * 7));
     return $user->tokens()->create(['expires_at' => $expiresAt, 'token' => $token]);
 }
Beispiel #2
0
 public function fire(array $data)
 {
     $this->validator->setScenario('register')->validate($data);
     $data['password'] = $this->hasher->make($data['password']);
     $user = $this->userModel->create($data);
     event(new UserRegistered($user));
     return $user;
 }
Beispiel #3
0
 public function fire(array $data)
 {
     $this->validator->setScenario('login')->validate($data);
     $user = $this->user->where('email', $data['email'])->first();
     if (!$this->hasher->check($data['password'], $user->password)) {
         throw new LoginFailedException();
     }
     return $user;
 }
Beispiel #4
0
 /**
  * Login user
  *
  * @param \Illuminate\Http\Request           $request
  * @param \Tajrish\Services\UserTokenHandler $tokenHandler
  * @param \Illuminate\Auth\Guard             $auth
  * @return \Illuminate\Http\JsonResponse
  */
 public function postLogin(Request $request, UserTokenHandler $tokenHandler, Guard $auth)
 {
     $this->validate($request, ['email' => 'required|email', 'password' => 'required|string']);
     // @FIXME Remove extra user call
     if ($auth->attempt($request->only(['email', 'password']))) {
         $user = User::where('email', $request['email'])->first();
         $token = $tokenHandler->createAndGetTokenForUser($user);
         return response()->json(['user' => $user, 'found' => true, 'token_entity' => $token, 'message' => trans('messages.successful_login')]);
     }
     return response()->json(['found' => false, 'message' => trans('messages.invalid_credentials')]);
 }
Beispiel #5
0
 protected function createUsers()
 {
     \Tajrish\Models\User::truncate();
     /** @var  \Tajrish\Repositories\UserTokenRepository $repo */
     $repo = app(\Tajrish\Repositories\UserTokenRepository::class);
     $user = \Tajrish\Models\User::create(['name' => 'رضا شادمان', 'email' => '*****@*****.**', 'password' => $pass = bcrypt('1234567'), 'province_id' => \Tajrish\Models\Province::where('name', 'تهران')->firstOrFail()->id]);
     $repo->makeUniqueTokenForUser($user, \Tajrish\Services\Tosan\Helpers\TokenGenerator::generate());
     $mockUsers = [['name' => 'تبسم لطیفی', 'email' => '*****@*****.**', 'password' => $pass], ['name' => 'سامان ولی زاده', 'email' => '*****@*****.**', 'password' => $pass], ['name' => 'سیاوش آقائی', 'email' => '*****@*****.**', 'password' => $pass], ['name' => 'علی یوسفی', 'email' => '*****@*****.**', 'password' => $pass], ['name' => 'حسین شعبانی', 'email' => '*****@*****.**', 'password' => $pass], ['name' => 'حامد دلفان', 'email' => '*****@*****.**', 'password' => $pass], ['name' => 'رضا کیانی', 'email' => '*****@*****.**', 'password' => $pass], ['name' => 'حامد بهداد', 'email' => '*****@*****.**', 'password' => $pass], ['name' => 'بهرام رادانس', 'email' => '*****@*****.**', 'password' => $pass], ['name' => 'رضا فروتن', 'email' => '*****@*****.**', 'password' => $pass], ['name' => 'هدیه تهرانی', 'email' => '*****@*****.**', 'password' => $pass]];
     foreach ($mockUsers as $user) {
         \Tajrish\Models\User::create(array_merge($user, ['province_id' => rand(1, 6)]));
         $repo->makeUniqueTokenForUser($user, \Tajrish\Services\Tosan\Helpers\TokenGenerator::generate());
     }
 }
Beispiel #6
0
 public function sendRecoveryEmail(array $data)
 {
     $this->validator->setScenario('forgotPassword')->validate($data);
     $user = $this->userModel->where('email', $data['email'])->first();
     return $this->sendEmail($user);
 }