public function post_login() { $credentials = array('email' => Input::get('username'), 'password' => Input::get('password')); $remember = Input::has('remember') ? true : false; $rules = array('email' => array('required', 'min:2'), 'password' => array('required', 'min:6')); $messages = array('email.required' => 'È necessario specificare il proprio username e la propria password per accedere', 'email.min' => 'Lo username deve essere lungo almeno 2 caratteri', 'password.required' => 'È necessario specificare il proprio username e la propria password per accedere', 'password.min' => 'La password deve essere lunga almeno 6 caratteri'); $validator = Validator::make($credentials, $rules, $messages); if ($validator->passes()) { try { $user = Sentry::findUserByCredentials($credentials); $groups = Group::all(); if ($user) { foreach ($groups as $group) { if ($user->inGroup($group->name)) { $userAuth = Sentry::authenticate($credentials, $remember); if ($userAuth) { return $this->make_response($credentials, false, array($user->first_name . ' ' . $user->first_last . ', Accesso ' . $group->name . ' consentito'), URL::to('admin/dashboard')); } } } } } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) { return $this->make_response($credentials, true, array('Non hai inserito la password')); } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { return $this->make_response($credentials, true, array('Utente non trovato')); } catch (Cartalyst\Sentry\Users\WrongPasswordException $e) { return $this->make_response($credentials, true, array('Password o nome utente non corretti')); } catch (\Exception $e) { return $this->make_response($credentials, true, array("errore non previsto: " . $e->getMessage())); } } else { $errors = $validator->messages; return $this->make_response($credentials, true, $errors); } }
/** * To edit member profile action * AccountController::postIndex() * * @return */ public function postIndex() { $this->userService = new UserAccountService(); $success_message = ""; $user = CUtil::getAuthUser(); $logged_user_id = $user->id; $input = \Input::all(); $input['user_id'] = $logged_user_id; $input['email'] = $user['email']; if (\Input::has('edit_basic')) { $rules = array(); $messages = array(); if (\Input::has('new_email') && \Input::get('new_email') != $user['email']) { $rules['new_email'] = $this->userService->getValidatorRule('email'); } if (\Input::get('password') != "" || \Input::get('password_confirmation') != "") { $rules['Oldpassword'] = '******'; } if (\Input::has('Oldpassword') && \Input::has('password') && \Input::get('password') != "" && \Input::get('Oldpassword') != \Input::get('password')) { $rules['Oldpassword'] = $this->userService->getValidatorRule('Oldpassword'); $messages['Oldpassword.is_valid_old_password'] = trans("myaccount/form.edit-profile.wrong_password"); $rules['password'] = $this->userService->getValidatorRule('password'); $rules['password_confirmation'] = 'Required|same:password'; } $validator = \Validator::make(\Input::all(), $rules, $messages); if ($validator->fails()) { return \Redirect::back()->withInput()->withErrors($validator); } else { $credential = array('email' => \Sentry::getUser()->email, 'password' => \Input::get('Oldpassword')); try { $user = \Sentry::findUserByCredentials($credential); $success_message = $this->userService->updateBasicDetails($input); } catch (sentrycheck $e) { return \Redirect::back()->withInput()->with('valid_user', \Lang::get('webshopauthenticate::myaccount/form.current_password')); } } } else { if (\Input::has('edit_personal')) { $rules = array(); $rules['first_name'] = $this->userService->getValidatorRule('first_name'); $rules['last_name'] = $this->userService->getValidatorRule('last_name'); $messages = array(); $validator = \Validator::make(\Input::all(), $rules, $messages); if ($validator->fails()) { return \Redirect::back()->withInput()->withErrors($validator); } $this->userService->updateUserPersonalDetails($input); $success_message = \Lang::get('webshopauthenticate::myaccount/form.edit-profile.personal_details_update_sucess'); } } return \Redirect::to(\Config::get('webshopauthenticate::uri') . '/myaccount')->with('success_message', $success_message); }
public function doLogin() { try { $user = Sentry::findUserByCredentials(array('email' => isset($_POST['email']) ? $_POST['email'] : '', 'password' => isset($_POST['password']) ? $_POST['password'] : '')); $remember = isset($_POST['remember']) ? true : false; Sentry::login($user, $remember); if (Session::get('redirectUri', false) !== false) { return Redirect::to(Session::get('redirectUri')); } else { return Redirect::route('check.index'); } } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) { Session::flash('error', trans('user.login.no-email')); } catch (Cartalyst\Sentry\Users\UserNotActivatedException $e) { Session::flash('error', trans('user.login.not-activated')); } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { Session::flash('error', trans('user.login.unknown')); } catch (Cartalyst\Sentry\Throttling\UserSuspendedException $e) { Session::flash('error', trans('user.login.suspended', $throttle->getSuspensionTime())); } catch (Cartalyst\Sentry\Throttling\UserBannedException $e) { Session::flash('error', trans('user.login.banned')); } return Redirect::back()->withInput(); }
public function postChangePassword(&$messageArray) { $validate = Validator::make(Input::all(), User::$changePasswordRules, User::$changePasswordLangs); if ($validate->passes()) { $oldPassword = Input::get('oldPassword'); $newPassword = Input::get('newPassword'); try { $userData = Sentry::findUserByCredentials(array('username' => Sentry::getUser()->username, 'password' => $oldPassword)); $userData->password = $newPassword; if ($userData->save()) { $messageArray['status'] = TRUE; $messageArray['message'] = "Đổi mật khẩu thành công"; } else { $messageArray['message'] = "Đã có lỗi xảy ra trong quá trình đổi mật khẩu. Bạn vui lòng thử lại sau"; } } catch (\Cartalyst\Sentry\Users\WrongPasswordException $e) { $messageArray['message'] = "Mật khẩu không chính xác"; } } else { $messageArray['validate'] = $validate->messages(); } }
public function findUserByCredentials($array) { return Sentry::findUserByCredentials($array); }
/** * Change new password */ public function postNewPassword($email, $key) { $valid = Validator::make(['email' => $email, 'key' => $key], ['email' => 'required|email|exists:users', 'key' => 'required|exists:users,reset_password_code']); if ($valid->fails()) { return Redirect::route('larauth.new_password', ['email' => $email, 'key' => $key])->with('errors', $valid->errors()); } $valid = Validator::make(['password' => Input::get('password'), 'password_confirmation' => Input::get('password_confirmation')], ['password' => 'required|confirmed|min:' . Config::get('larauth::registration.min_password')], ['key.required' => trans('larauth::larauth,process_key_required'), 'password.required' => trans('larauth::larauth.password_required'), 'password.confirmed' => trans('larauth::larauth.password_confirmed'), 'password.min' => trans('larauth::larauth.password_min', ['min' => Config::get('larauth::registration.min_password')])]); if ($valid->fails()) { return Redirect::route('larauth.new_password', ['email' => $email, 'key' => $key])->with('errors', $valid->errors()); } $user = Sentry::findUserByCredentials(['email' => $email]); if ($user->attemptResetPassword($key, Input::get('password'))) { return Redirect::route('larauth.new_password')->with('processed', true); } }