/**
  * 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.');
     }
 }
示例#2
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', '/'));
 }
示例#3
0
 /**
  * Logs the user in.
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function postLogin()
 {
     if (Auth::attempt(Binput::only(['email', 'password']))) {
         return Redirect::intended('dashboard');
     }
     Throttle::hit(Request::instance(), 10, 10);
     return Redirect::back()->withInput(Binput::except('password'))->with('error', 'Invalid email or password');
 }
示例#4
0
 /**
  * Update an existing incident.
  *
  * @param \CachetHQ\Cachet\Models\Inicdent $incident
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function putIncident(Incident $incident)
 {
     $incidentData = array_filter(Binput::only(['name', 'message', 'status', 'component_id', 'notify', 'visible']));
     try {
         $incident->update($incidentData);
     } catch (Exception $e) {
         throw new BadRequestHttpException();
     }
     return $this->item($incident);
 }
 /**
  * Update an existing group.
  *
  * @param \CachetHQ\Cachet\Models\ComponentGroup $group
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function putGroup(ComponentGroup $group)
 {
     $groupData = array_filter(Binput::only(['name', 'order']));
     try {
         $group->update($groupData);
     } catch (Exception $e) {
         throw new BadRequestHttpException();
     }
     return $this->item($group);
 }
示例#6
0
 /**
  * Updates a user.
  *
  * @param \Gitamin\Models\User $user
  *
  * @return \Illuminate\View\View
  */
 public function postUpdateUser(User $user)
 {
     $userData = array_filter(Binput::only(['username', 'email', 'password', 'level']));
     try {
         $user->update($userData);
     } catch (ValidationException $e) {
         return Redirect::route('dashboard.group.edit', ['id' => $user->id])->withInput($userData)->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.group.edit.failure')))->withErrors($e->getMessageBag());
     }
     return Redirect::route('dashboard.group.edit', ['id' => $user->id])->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.group.edit.success')));
 }
 /**
  * Update an existing group.
  *
  * @param \CachetHQ\Cachet\Models\ComponentGroup $group
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function putGroup(ComponentGroup $group)
 {
     $groupData = array_filter(Binput::only(['name', 'order']));
     try {
         $group = $this->dispatch(new UpdateComponentGroupCommand($group, Binput::get('name'), Binput::get('order', 0)));
     } catch (Exception $e) {
         throw new BadRequestHttpException();
     }
     return $this->item($group);
 }
示例#8
0
 /**
  * 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);
 }
示例#9
0
 /**
  * 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.');
 }
示例#10
0
 /**
  * Logs the user in.
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function postLogin()
 {
     $loginData = Binput::only(['email', 'password']);
     // Validate login credentials.
     if (Auth::validate($loginData)) {
         // Log the user in for one request.
         Auth::once($loginData);
         // We probably want to add support for "Remember me" here.
         Auth::attempt($loginData);
         return Redirect::intended('dashboard');
     }
     return Redirect::route('auth.login')->withInput(Binput::except('password'))->withError(trans('forms.login.invalid'));
 }
示例#11
0
 /**
  * Updates the current user.
  *
  * @return \Illuminate\View\View
  */
 public function postUser()
 {
     $userData = array_filter(Binput::only(['username', 'email', 'password', 'google2fa']));
     $enable2FA = (bool) array_pull($userData, 'google2fa');
     // Let's enable/disable auth
     if ($enable2FA && !Auth::user()->hasTwoFactor) {
         $userData['google_2fa_secret'] = Google2FA::generateSecretKey();
     } elseif (!$enable2FA) {
         $userData['google_2fa_secret'] = '';
     }
     try {
         Auth::user()->update($userData);
     } catch (ValidationException $e) {
         return Redirect::route('dashboard.user')->withInput($userData)->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.team.edit.failure')))->withErrors($e->getMessageBag());
     }
     return Redirect::route('dashboard.user')->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.team.edit.success')));
 }
示例#12
0
 /**
  * Logs the user in.
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function postLogin()
 {
     $loginData = Binput::only(['email', 'password']);
     // Validate login credentials.
     if (Auth::validate($loginData)) {
         // Log the user in for one request.
         Auth::once($loginData);
         // Do we have Two Factor Auth enabled?
         if (Auth::user()->hasTwoFactor) {
             // Temporarily store the user.
             Session::put('2fa_id', Auth::user()->id);
             return Redirect::route('auth.two-factor');
         }
         // We probably want to add support for "Remember me" here.
         Auth::attempt($loginData);
         return Redirect::intended('dashboard');
     }
     return Redirect::route('auth.login')->withInput(Binput::except('password'))->withError(trans('forms.login.invalid'));
 }
示例#13
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.');
     }
 }
示例#14
0
 /**
  * Update an existing event.
  *
  * @param int $id
  *
  * @return \Illuminate\Http\Response
  */
 public function update($id)
 {
     $input = Binput::only(['title', 'location', 'date', 'body']);
     $val = $val = EventRepository::validate($input, array_keys($input));
     if ($val->fails()) {
         return Redirect::route('events.edit', ['events' => $id])->withInput()->withErrors($val->errors());
     }
     $input['date'] = Carbon::createFromFormat(Config::get('date.php_format'), $input['date']);
     $event = EventRepository::find($id);
     $this->checkEvent($event);
     $event->update($input);
     return Redirect::route('events.show', ['events' => $event->id])->with('success', 'Your event has been updated successfully.');
 }
示例#15
0
 /**
  * Update an existing post.
  *
  * @param int $id
  *
  * @return \Illuminate\Http\Response
  */
 public function update($id)
 {
     $input = Binput::only(['title', 'summary', 'body']);
     $val = PostRepository::validate($input, array_keys($input));
     if ($val->fails()) {
         return Redirect::route('blog.posts.edit', ['posts' => $id])->withInput()->withErrors($val->errors());
     }
     $post = PostRepository::find($id);
     $this->checkPost($post);
     $post->update($input);
     return Redirect::route('blog.posts.show', ['posts' => $post->id])->with('success', 'Your post has been updated successfully.');
 }
示例#16
0
 /**
  * Update an existing user.
  *
  * @param int $id
  *
  * @return \Illuminate\Http\Response
  */
 public function update($id)
 {
     $input = Binput::only(['first_name', 'last_name', 'email']);
     $val = UserRepository::validate($input, array_keys($input));
     if ($val->fails()) {
         return Redirect::route('users.edit', ['users' => $id])->withInput()->withErrors($val->errors());
     }
     $user = UserRepository::find($id);
     $this->checkUser($user);
     $email = $user['email'];
     $user->update($input);
     $groups = GroupRepository::index();
     $changed = false;
     foreach ($groups as $group) {
         if ($user->inGroup($group)) {
             if (Binput::get('group_' . $group->id) !== 'on') {
                 $user->removeGroup($group);
                 $changed = true;
             }
         } else {
             if (Binput::get('group_' . $group->id) === 'on') {
                 $user->addGroup($group);
                 $changed = true;
             }
         }
     }
     if ($email !== $input['email']) {
         $mail = ['old' => $email, 'new' => $input['email'], 'url' => URL::to(Config::get('core.home', '/')), 'subject' => Config::get('core.name') . ' - New Email Information'];
         Mail::queue('emails.newemail', $mail, function ($message) use($mail) {
             $message->to($mail['old'])->subject($mail['subject']);
         });
         Mail::queue('emails.newemail', $mail, function ($message) use($mail) {
             $message->to($mail['new'])->subject($mail['subject']);
         });
     }
     if ($changed) {
         $mail = ['url' => URL::to(Config::get('core.home', '/')), 'email' => $input['email'], 'subject' => Config::get('core.name') . ' - Group Membership Changes'];
         Mail::queue('emails.groups', $mail, function ($message) use($mail) {
             $message->to($mail['email'])->subject($mail['subject']);
         });
     }
     return Redirect::route('users.show', ['users' => $user->id])->with('success', 'The user has been updated successfully.');
 }
示例#17
0
 /**
  * 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.');
     }
 }
示例#18
0
 /**
  * Update the user's password.
  *
  * @return \Illuminate\Http\Response
  */
 public function patchPassword()
 {
     $input = Binput::only(['password', 'password_confirmation']);
     $val = UserRepository::validate($input, array_keys($input));
     if ($val->fails()) {
         return Redirect::route('account.profile')->withInput()->withErrors($val->errors());
     }
     unset($input['password_confirmation']);
     $user = Credentials::getUser();
     $this->checkUser($user);
     $mail = ['url' => URL::to(Config::get('core.home', '/')), 'email' => $user->getLogin(), 'subject' => Config::get('core.name') . ' - New Password Notification'];
     Mail::queue('emails.newpass', $mail, function ($message) use($mail) {
         $message->to($mail['email'])->subject($mail['subject']);
     });
     $user->update($input);
     return Redirect::route('account.profile')->with('success', 'Your password has been updated successfully.');
 }