/** * Execute the job. * * @param JWT $jwt * @param Carbon $carbon * @return String */ public function handle(JWT $jwt, Carbon $carbon) { $timestamp = $carbon->now()->timestamp; $data = collect($this->user->toArray())->only('id')->merge(compact('timestamp')); $token = $jwt->encode($data, env('APP_KEY')); /** * Save token on the user model */ if ($this->saveToken) { $this->user->setAttribute('api_token', $token); $this->user->save(); } return $token; }
public function sendResetPasswordInfo(User $user, PasswordResetToken $passwordResetToken) { Mail::queue('emails.reset_password_info', ['user' => $user, 'passwordResetToken' => $passwordResetToken, 'link' => $passwordResetToken->getResetPasswordLink()], function ($message) use($user, $passwordResetToken) { $transParams = array_dot($user->toArray()); $transParams['app_name'] = trans('base.app.name'); $message->to($passwordResetToken->email, $user->username)->subject(trans('reset_password.request_code.email.subject', $transParams)); }); }
public function fillFromEloquent(User $user) { $this->eloquent = $user; $attributes = $user->toArray(); if (isset($this->username)) { unset($attributes['username']); } $this->fill($attributes); }
public function transform(User $user) { return $user->toArray(); }
/** * Generate a jwt token for user * @param User $user * @param bool $rememberMe * @param bool $jwtCookie * @return string */ public function generateUserToken($user, $rememberMe = false, $jwtCookie = false) { $data = ["sub" => (int) $user->id, "user" => $user->toArray(), "rememberMe" => (int) $rememberMe, "auth" => $this->calculateAuthHash($user)]; // compute exp $ttl = $rememberMe ? $this->ttlRememberMe : $this->ttl; $data["exp"] = is_string($ttl) ? strtotime($ttl) : time() + $ttl; // compute csrf if using cookie if ($jwtCookie) { $data["csrf"] = $this->request->getCsrfToken(); } $token = $this->encode($data); if ($jwtCookie) { $this->addCookieToken($this->tokenParam, $token, $data["exp"]); } return $token; }
/** * store a resource * @param Request $this->request http request * @param mixed $id id of the resource for updating * @return jsend jsend with newly stored source */ function store($id = null) { //////////////// // Load Data // //////////////// if ($id) { $data = Model::find($id); if (!$data) { return app()->abort(404); } } else { $data = new Model(); } /////////////////////////////////// // Assign posted data to Data // /////////////////////////////////// $data->fill($this->request->input()); /////////////////////// // EMBED IMAGES // /////////////////////// foreach ($this->request->input('images') as $x) { $images[] = new Image($x); } if (!$data->syncImages($images)) { return response()->json(JSend::fail($data->getErrors())->asArray())->setCallback($this->request->input('callback')); } /////////////////////// // EMBED AUTH // /////////////////////// foreach ($this->request->input('auths') as $x) { $auths[] = new Auth($x); } if (!$data->syncAuths($auths)) { return response()->json(JSend::fail($data->getErrors())->asArray())->setCallback($this->request->input('callback')); } /////////////////////// // EMBED ACCOUNT // /////////////////////// foreach ($this->request->input('account_connects') as $x) { $accounts[] = new AccountConnect($x); } if (!$data->syncAccountConnects($accounts)) { return response()->json(JSend::fail($data->getErrors())->asArray())->setCallback($this->request->input('callback')); } /////////// // Store // /////////// if ($data->save()) { ///////////////////// // Return Response // ///////////////////// return response()->json(JSend::success(['data' => $data->toArray()])->asArray()); } else { return response()->json(JSend::fail($data->getErrors())->asArray()); } }