Exemple #1
0
 /**
  * Attempt to login the specified user.
  *
  * @return \Illuminate\Http\Response
  */
 public function postLogin()
 {
     $remember = Binput::get('rememberMe');
     $input = Binput::only(['email', 'password']);
     $rules = UserRepository::rules(array_keys($input));
     $rules['password'] = '******';
     $val = UserRepository::validate($input, $rules, true);
     if ($val->fails()) {
         return Redirect::route('account.login')->withInput()->withErrors($val->errors());
     }
     $this->throttler->hit();
     try {
         $throttle = Credentials::getThrottleProvider()->findByUserLogin($input['email']);
         $throttle->check();
         Credentials::authenticate($input, $remember);
     } catch (WrongPasswordException $e) {
         return Redirect::route('account.login')->withInput()->withErrors($val->errors())->with('error', 'Your password was incorrect.');
     } catch (UserNotFoundException $e) {
         return Redirect::route('account.login')->withInput()->withErrors($val->errors())->with('error', 'That user does not exist.');
     } catch (UserNotActivatedException $e) {
         if (Config::get('credentials::activation')) {
             return Redirect::route('account.login')->withInput()->withErrors($val->errors())->with('error', 'You have not yet activated this account.');
         } else {
             $throttle->user->attemptActivation($throttle->user->getActivationCode());
             $throttle->user->addGroup(Credentials::getGroupProvider()->findByName('Users'));
             return $this->postLogin();
         }
     } catch (UserSuspendedException $e) {
         $time = $throttle->getSuspensionTime();
         return Redirect::route('account.login')->withInput()->withErrors($val->errors())->with('error', "Your account has been suspended for {$time} minutes.");
     } catch (UserBannedException $e) {
         return Redirect::route('account.login')->withInput()->withErrors($val->errors())->with('error', 'You have been banned. Please contact support.');
     }
     return Redirect::intended(Config::get('core.home', '/'));
 }
 /**
  * Attempt to register a new user.
  *
  * @return \Illuminate\Http\Response
  */
 public function postRegister()
 {
     if (!Config::get('credentials.regallowed')) {
         return Redirect::route('account.register');
     }
     $input = Binput::only(['first_name', 'last_name', 'email', 'password', 'password_confirmation']);
     $val = UserRepository::validate($input, array_keys($input));
     if ($val->fails()) {
         return Redirect::route('account.register')->withInput()->withErrors($val->errors());
     }
     $this->throttler->hit();
     try {
         unset($input['password_confirmation']);
         $user = Credentials::register($input);
         if (!Config::get('credentials.activation')) {
             $mail = ['url' => URL::to(Config::get('credentials.home', '/')), 'email' => $user->getLogin(), 'subject' => Config::get('app.name') . ' - Welcome'];
             Mail::queue('credentials::emails.welcome', $mail, function ($message) use($mail) {
                 $message->to($mail['email'])->subject($mail['subject']);
             });
             $user->attemptActivation($user->getActivationCode());
             $user->addGroup(Credentials::getGroupProvider()->findByName('Users'));
             return Redirect::to(Config::get('credentials.home', '/'))->with('success', 'Your account has been created successfully. You may now login.');
         }
         $code = $user->getActivationCode();
         $mail = ['url' => URL::to(Config::get('credentials.home', '/')), 'link' => URL::route('account.activate', ['id' => $user->id, 'code' => $code]), 'email' => $user->getLogin(), 'subject' => Config::get('app.name') . ' - Welcome'];
         Mail::queue('credentials::emails.welcome', $mail, function ($message) use($mail) {
             $message->to($mail['email'])->subject($mail['subject']);
         });
         return Redirect::to(Config::get('credentials.home', '/'))->with('success', 'Your account has been created. Check your email for the confirmation link.');
     } catch (UserExistsException $e) {
         return Redirect::route('account.register')->withInput()->withErrors($val->errors())->with('error', 'That email address is taken.');
     }
 }
 /**
  * Submit the contact form.
  *
  * @return \Illuminate\Http\Response
  */
 public function postSubmit()
 {
     $rules = ['first_name' => 'required', 'last_name' => 'required', 'email' => 'required', 'message' => 'required'];
     $input = Binput::only(array_keys($rules));
     $val = Validator::make($input, $rules);
     if ($val->fails()) {
         return Redirect::to($this->path)->withInput()->withErrors($val);
     }
     $this->throttler->hit();
     Mailer::send($input['first_name'], $input['last_name'], $input['email'], $input['message']);
     return Redirect::to('/')->with('success', 'Your message was sent successfully. Thank you for contacting us.');
 }
 /**
  * Store a new comment.
  *
  * @param int $postId
  *
  * @throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function store($postId)
 {
     $input = array_merge(Binput::only('body'), ['user_id' => Credentials::getuser()->id, 'post_id' => $postId, 'version' => 1]);
     if (CommentRepository::validate($input, array_keys($input))->fails()) {
         throw new BadRequestHttpException('Your comment was empty.');
     }
     $this->throttler->hit();
     $comment = CommentRepository::create($input);
     $contents = View::make('posts.comment', ['comment' => $comment, 'post_id' => $postId]);
     return Response::json(['success' => true, 'msg' => 'Comment created successfully.', 'contents' => $contents->render(), 'comment_id' => $comment->id], 201);
 }
Exemple #5
0
 /**
  * Queue the sending of the password reset email.
  *
  * @return \Illuminate\Http\Response
  */
 public function postReset()
 {
     $input = Binput::only('email');
     $val = UserRepository::validate($input, array_keys($input));
     if ($val->fails()) {
         return Redirect::route('account.reset')->withInput()->withErrors($val->errors());
     }
     $this->throttler->hit();
     try {
         $user = Credentials::getUserProvider()->findByLogin($input['email']);
         $code = $user->getResetPasswordCode();
         $mail = ['link' => URL::route('account.password', ['id' => $user->id, 'code' => $code]), 'email' => $user->getLogin(), 'subject' => Config::get('core.name') . ' - Password Reset Confirmation'];
         Mail::queue('emails.reset', $mail, function ($message) use($mail) {
             $message->to($mail['email'])->subject($mail['subject']);
         });
         return Redirect::route('account.reset')->with('success', 'Check your email for password reset information.');
     } catch (UserNotFoundException $e) {
         return Redirect::route('account.reset')->with('error', 'That user does not exist.');
     }
 }
 /**
  * Queue the sending of the activation email.
  *
  * @return \Illuminate\Http\Response
  */
 public function postResend()
 {
     $input = Binput::only('email');
     $val = UserRepository::validate($input, array_keys($input));
     if ($val->fails()) {
         return Redirect::route('account.resend')->withInput()->withErrors($val->errors());
     }
     $this->throttler->hit();
     try {
         $user = Credentials::getUserProvider()->findByLogin($input['email']);
         if ($user->activated) {
             return Redirect::route('account.resend')->withInput()->with('error', 'That user is already activated.');
         }
         $code = $user->getActivationCode();
         $mail = ['url' => URL::to(Config::get('credentials.home', '/')), 'link' => URL::route('account.activate', ['id' => $user->id, 'code' => $code]), 'email' => $user->getLogin(), 'subject' => Config::get('app.name') . ' - Activation'];
         Mail::queue('credentials::emails.resend', $mail, function ($message) use($mail) {
             $message->to($mail['email'])->subject($mail['subject']);
         });
         return Redirect::route('account.resend')->with('success', 'Check your email for your new activation email.');
     } catch (UserNotFoundException $e) {
         return Redirect::route('account.resend')->with('error', 'That user does not exist.');
     }
 }