Пример #1
0
 /**
  * @param $credentials
  * @throws ValidationFailed
  */
 public function validate($credentials)
 {
     $valid = Auth::validate($credentials);
     if (!$valid) {
         throw new ValidationFailed();
     }
 }
 /**
  * @return Redirect
  */
 public function login()
 {
     $rules = array('email' => 'required', 'password' => 'required');
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return redirect('/')->withErrors($validator);
     } else {
         $user = array('email' => Input::get('email'), 'password' => Input::get('password'));
         if (Auth::validate($user)) {
             if (Auth::attempt($user)) {
                 // Grab Authenticated User's Data Once
                 $user_data = Auth::user();
                 Session::put('user_id', $user_data->id);
                 Session::put('name', $user_data->name);
                 Session::put('email_id', $user_data->email);
                 return redirect::to('settings');
             }
         } else {
             /*Session::flash('message','Login Failed');
               return redirect('auth/login');*/
             return Redirect::back()->withInput()->withErrors('That Email/password does not exist.');
         }
     }
     /* $email = Input::get('email');
             $password = Input::get('password');
     
             if (Auth::attempt(['email' => $email, 'password' => $password]))
             {
                 return Redirect::intended('/settings/index');
             }
     
             return Redirect::back()
                 ->withInput()
                 ->withErrors('That Email/password combo does not exist.');*/
 }
Пример #3
0
 public function verifyByDocumentation($username, $password)
 {
     if (Auth::validate(['email' => $username, 'password' => $password])) {
         $user = \App\User::where('email', $username)->first();
         return $user->id;
     } else {
         return false;
     }
 }
Пример #4
0
 public function verify($username, $password)
 {
     $credentials = ['email' => $username, 'password' => $password];
     $valid = Auth::validate($credentials);
     if ($valid) {
         return Auth::getProvider()->retrieveByCredentials($credentials)->id;
     }
     return false;
 }
 public function update_password($username, PasswordChangeRequest $request)
 {
     if (Auth::validate(['phone' => Auth::user()->phone, 'password' => $request->input('old_password')])) {
         Auth::user()->password = bcrypt($request->input('password'));
         Auth::user()->save();
         return redirect()->back()->with('success', 'Password updated successfully');
     } else {
         return redirect()->back()->with('error', 'Current password do not match with one in our record!');
     }
 }
 public function doLogin()
 {
     // validate the info, create rules for the inputs
     $rules = array('username' => 'required|min:5', 'password' => 'required|min:6');
     // run the validation rules on the inputs from the form
     $validator = Validator::make(Input::all(), $rules);
     // if the validator fails, redirect back to the form
     if ($validator->fails()) {
         return Redirect::route(UserItem::loginRoute(), UserItem::loginRouteParams())->withErrors($validator)->withInput(Input::except('password'));
         // send back the input (not the password) so that we can repopulate the form
     } else {
         // create our user data for the authentication
         $userdata = array('username' => Input::get('username'), 'password' => Input::get('password'));
         // attempt to do the login
         if (Auth::validate($userdata)) {
             //  Valid Login
             $valid_login = true;
             //  Get User
             $user = UserItem::findUser($userdata["username"]);
             //  Check if User Disabled
             if (!$user->isEnabled()) {
                 return Redirect::route(UserItem::loginRoute(), UserItem::loginRouteParams())->with(FLASH_MSG_ERROR, trans("auth-module::message.account_disabled"));
             }
             //  Trigger Login Event & Validate
             mergeEventFireResponse(true, Event::fire('user.login_validate', array($user, &$valid_login)));
             //  Check Valid
             if ($valid_login) {
                 //  Do Login
                 Auth::login($user);
                 //  Add Login Log
                 LoginLogItem::addLog($user, true);
                 //  Trigger Valid Login Event
                 Event::fire('user.valid_login', array($user));
                 // validation successful!
                 return Redirect::intended(URL::route(UserItem::dashboardRoute()))->with(FLASH_MSG_INFO, trans("auth-module::message.success_login"));
             } else {
                 //  Add Login Log
                 LoginLogItem::addLog($user, false);
                 //  Trigger Invalid Login Event
                 Event::fire('user.invalid_login', array($userdata['username']));
                 // validation not successful, send back to form
                 return Redirect::route(UserItem::loginRoute(), UserItem::loginRouteParams())->with(FLASH_MSG_ERROR, trans("auth-module::message.invalid_login"))->withInput(Input::except('password'));
             }
         } else {
             //  Add Login Log
             LoginLogItem::addLogUsername($userdata["username"], false);
             //  Trigger Invalid Login Event
             Event::fire('user.invalid_login', array(Input::get('username')));
             // validation not successful, send back to form
             return Redirect::route(UserItem::loginRoute(), UserItem::loginRouteParams())->with(FLASH_MSG_ERROR, trans("auth-module::message.invalid_login"))->withInput(Input::except('password'));
         }
     }
 }
Пример #7
0
 public function verify($username, $password)
 {
     $credentials = ['email' => $username, 'password' => $password];
     if (Auth::validate($credentials)) {
         $user = \CodeProject\Entities\User::where('email', $username)->first();
         return $user->id;
     }
     /*      if (Auth::once($credentials)) {
               return Auth::user()->id;
           }*/
     return false;
 }
Пример #8
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'));
 }
Пример #9
0
 /**
  * Reset the current user's password.
  * @return Redirect
  */
 public function postReset()
 {
     $current_user = Auth::user();
     if (!Auth::validate(array('username' => Auth::user()->username, 'password' => Input::get('current_password')))) {
         return Redirect::back()->with('flash_error', 'Your current password does not match, please <a href="#password"> try again</a>!');
     }
     $validator = Validator::make(array('new_password' => Input::get('new_password'), 'new_password_confirmation' => Input::get('new_password_conf')), array('new_password' => 'required|min:5|confirmed'));
     if ($validator->passes()) {
         $current_user->password = Hash::make(Input::get('new_password'));
         $current_user->save();
         return Redirect::back()->with('flash_success', 'Your password has been updated successfully!');
     }
     return Redirect::back()->with('flash_error', 'Your new passwords do not match or your new password does not meet the minimum length five characters, please <a href="#password"> try again</a>!');
 }
Пример #10
0
 /**
  * @param array $data
  * @param bool $rememberMe
  * @param bool $login
  *
  * @return User|false
  */
 public function attemptToSignIn(array $data, $rememberMe = false, $login = false)
 {
     if (!Auth::validate(array_only($data, ['email', 'password']))) {
         Flash::error(trans('ahk_messages.credentials_mismatch'));
         return false;
     }
     $user = $this->findByEmail($data['email']);
     if (!$user->verified) {
         Flash::error(trans('ahk_messages.please_validate_your_email_first'));
         return false;
     }
     Auth::login($user);
     return $user;
 }
Пример #11
0
 /**
  * Logs the user in.
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function loginPost()
 {
     $loginData = Request::only(['login', 'password']);
     // Login with username or email.
     $loginKey = Str::contains($loginData['login'], '@') ? 'email' : 'username';
     $loginData[$loginKey] = array_pull($loginData, 'login');
     // 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('/')
         return Redirect::home()->withSuccess(trans('gitamin.signin.success'));
     }
     return Redirect::route('auth.login')->withInput(Request::except('password'))->withError(trans('gitamin.signin.invalid'));
 }
Пример #12
0
 public function changePassword(Request $request)
 {
     $validator = Validator::make($request->all(), ['current_password' => 'required', 'password' => 'required|confirmed|min:6']);
     if ($validator->fails()) {
         return redirect('/admin/changePassword')->with('errors', $validator->errors()->all());
     } else {
         $user = Auth::user();
         $credentials = ['email' => $user->email, 'password' => $request->get('current_password')];
         $valid = Auth::validate($credentials);
         if ($valid) {
             $user->password = bcrypt($request->get('password'));
             $user->save();
             $request->session()->flash("notif", "Password successfully changed!");
             return redirect('/profile');
         }
         return redirect('/admin/changePassword')->with('errors', ['Input correct current password']);
     }
 }
Пример #13
0
 /**
  * Persist the changes.
  *
  * @param User $user
  *
  * @throws InvalidPasswordException
  * @throws UnableToChangePasswordException
  *
  * @return bool
  */
 public function persist(User $user)
 {
     $credentials['password'] = $this->input('current_password');
     $credentials['email'] = $user->email;
     if (!Auth::validate($credentials)) {
         throw new InvalidPasswordException();
     }
     if ($user->from_ad) {
         // If the user is from active directory, we won't
         // allow them to change their password.
         throw new UnableToChangePasswordException();
     }
     // Change the users password.
     $user->password = $this->input('password');
     if (!$user->save()) {
         throw new UnableToChangePasswordException();
     }
 }
 public function ChangePassword(ChangePassRequest $request)
 {
     if (Auth::check()) {
         $customer_data = ["email" => Auth::user()->email, "password" => $request->password_old];
         /*kiem tra mat khau cu*/
         if (Auth::validate($customer_data)) {
             //dung mat khau
             $customer = customer::find(Auth::user()->id);
             $customer->password = Hash::make($request->password);
             $customer->save();
             Auth::logout();
             return redirect()->route("login");
         } else {
             return redirect()->route("thongtin.template")->with("result", "Mật khẩu không chính xác");
         }
     } else {
         return redirect()->route("login");
     }
 }
Пример #15
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'));
 }
Пример #16
0
 /**
  * Handle a login request to the application.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function postLogin(Request $request)
 {
     $this->validate($request, [$this->loginUsername() => 'required', 'password' => 'required']);
     // If the class is using the ThrottlesLogins trait, we can automatically throttle
     // the login attempts for this application. We'll key this by the username and
     // the IP address of the client making these requests into this application.
     $throttles = $this->isUsingThrottlesLoginsTrait();
     if ($throttles && $this->hasTooManyLoginAttempts($request)) {
         return $this->sendLockoutResponse($request);
     }
     $credentials = $this->getCredentials($request);
     if (Auth::validate($credentials)) {
         return $this->handleUserWasAuthenticated($request, $throttles);
     }
     // If the login attempt was unsuccessful we will increment the number of attempts
     // to login and redirect the user back to the login form. Of course, when this
     // user surpasses their maximum number of attempts they will get locked out.
     if ($throttles) {
         $this->incrementLoginAttempts($request);
     }
     return redirect($this->loginPath())->withInput($request->only($this->loginUsername(), 'remember'))->withErrors([$this->loginUsername() => $this->getFailedLoginMessage()]);
 }
Пример #17
0
 /**
  * Logs the user in.
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function postLogin()
 {
     $userData = Input::only(['login', 'password', 'verifycode']);
     $verifycode = array_pull($userData, 'verifycode');
     if ($verifycode != Session::get('phrase')) {
         // instructions if user phrase is good
         return Redirect::to('auth/login')->withInput(Input::except('password'))->withErrors(trans('gitamin.captcha.failure'));
     }
     // Login with username or email.
     $loginKey = Str::contains($userData['login'], '@') ? 'email' : 'username';
     $userData[$loginKey] = array_pull($userData, 'login');
     // Validate login credentials.
     if (Auth::validate($userData)) {
         // We probably want to add support for "Remember me" here.
         Auth::attempt($userData, false);
         if (Session::has('connect_data')) {
             $connect_data = Session::get('connect_data');
             dispatch(new AddIdentityCommand(Auth::user()->id, $connect_data));
         }
         return Redirect::intended('/')->withSuccess(sprintf('%s %s', trans('gitamin.awesome'), trans('gitamin.login.success')));
     }
     return redirect('/auth/login')->withInput(Input::except('password'))->withErrors(trans('gitamin.login.invalid'));
 }
 public function login(Request $request)
 {
     $this->validate($request, [$this->loginUsername() => 'required', 'password' => 'required']);
     // If the class is using the ThrottlesLogins trait, we can automatically throttle
     // the login attempts for this application. We'll key this by the username and
     // the IP address of the client making these requests into this application.
     $throttles = $this->isUsingThrottlesLoginsTrait();
     if ($throttles && $this->hasTooManyLoginAttempts($request)) {
         return $this->sendLockoutResponse($request);
     }
     $credentials = $this->getCredentials($request);
     //  if (Auth::attempt($credentials, $request->has('remember'))) {
     //      $this->swapUserSession(Auth::user());
     //      return $this->handleUserWasAuthenticated($request, $throttles);
     //  }
     if (Auth::validate($credentials)) {
         $user = Auth::getLastAttempted();
         $previous_session = $user->last_session_id;
         if ($previous_session) {
             \Session::getHandler()->destroy($previous_session);
             Auth::setUser($user);
             Auth::logout();
         }
         Auth::login($user, $request->has('remember'));
         $user->last_session_id = \Session::getId();
         $user->save();
         return redirect()->intended($this->redirectPath());
     }
     // If the login attempt was unsuccessful we will increment the number of attempts
     // to login and redirect the user back to the login form. Of course, when this
     // user surpasses their maximum number of attempts they will get locked out.
     if ($throttles) {
         $this->incrementLoginAttempts($request);
     }
     return redirect()->back()->withInput($request->only($this->loginUsername(), 'remember'))->withErrors([$this->loginUsername() => $this->getFailedLoginMessage()]);
 }
 public function login()
 {
     // Getting all post data
     $data = Input::all();
     // Applying validation rules.
     $rules = array('email' => 'required|email', 'password' => 'required');
     $validator = Validator::make($data, $rules);
     if ($validator->fails()) {
         // If validation falis redirect back to login.
         return \Redirect::to('admin/login')->withInput(Input::except('password'))->withErrors($validator);
     } else {
         $userdata = array('email' => Input::get('email'), 'password' => Input::get('password'));
         // doing login.
         if (Auth::validate($userdata)) {
             if (Auth::attempt($userdata)) {
                 return \Redirect::intended('admin/contacts');
             }
         } else {
             // if any error send back with message.
             Session::flash('error', 'Something went wrong');
             return \Redirect::to('admin/login');
         }
     }
 }
Пример #20
0
 public function resetPassword($id)
 {
     // ----------------------------------------
     $user = User::find(Auth::id());
     $created = $user->tasks_created;
     $completed = $user->tasks_completed;
     if ($created == "") {
         $created = 0;
     }
     if ($completed == "") {
         $completed = 0;
     }
     // ----------------------------------------
     $current_pwd = Input::get('current_pwd');
     $new_pwd = Input::get('new_pwd');
     // lets validate the users input
     $validator = Validator::make(array('current_pwd' => $current_pwd, 'new_pwd' => $new_pwd), array('current_pwd' => 'required', 'new_pwd' => 'required'));
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->with('user', $user)->with('created', $created)->with('completed', $completed);
     }
     if (!Auth::validate(array('email' => $user->email, 'password' => $current_pwd))) {
         $validator->getMessageBag()->add('password', 'That password is incorrect');
         return Redirect::back()->withErrors($validator)->with('user', $user)->with('created', $created)->with('completed', $completed);
     }
     // Store the new password and redirect;
     $user->password = Hash::make($new_pwd);
     $user->save();
     return Redirect::back()->with('user', $user)->with('created', $created)->with('completed', $completed)->with('success', "Your password has been updated!");
 }
 /**
  * @param Request $request
  * @return $this|\Illuminate\View\View
  */
 public function update_password(Request $request)
 {
     $this->validate($request, ["old_password" => "required|min:6", "password" => "required|min:6|confirmed"]);
     $old = $request->get('old_password');
     $new = $request->get('password');
     //        return \Auth::user()->id;
     $userdata = array('id' => \Auth::user()->id, 'password' => $old);
     // doing login.
     if (Auth::validate($userdata)) {
         if (Auth::attempt($userdata)) {
             //Session::flash('success', 'Successfully changed your password.');
             $user = \Auth::user();
             $user->password = bcrypt($new);
             $user->update();
             Session::flash('status', 'You have successfully changed your password.');
             return view('user.password');
         }
     } else {
         // if any error send back with message.
         //            Session::flash('error', 'Something went wrong');
         return view('user.password')->withErrors(["msg" => "The old password was incorrect."]);
     }
 }
Пример #22
0
 public function doLogin(Request $request)
 {
     // Applying validation rules.
     $userdata = array('username' => Input::get('username'), 'password' => Input::get('password'), 'is_active' => 1);
     // doing login.
     if (Auth::validate($userdata)) {
         if (Auth::attempt($userdata)) {
             $exchangerate = DB::table('exchange_rates')->orderBy('id', 'desc')->first();
             $request->session()->put('exchangerate', $exchangerate);
             $getUserLocation = DB::table('user_locations')->join('locations', 'locations.id', '=', 'location_id')->where('user_id', Auth::user()->id)->first();
             $userGroup = DB::table('user_groups')->where('user_id', Auth::user()->id)->first();
             $request->session()->put('location_id', $getUserLocation->location_id);
             $request->session()->put('location_name', $getUserLocation->name);
             $request->session()->put('group_id', $userGroup->group_id);
             // Add to user sale log
             $userSaleLog = new UserSaleLog();
             $userSaleLog->user_id = Auth::user()->id;
             $userSaleLog->dates = date('Y-m-d');
             $userSaleLog->time_in = date('H:i:s');
             $userSaleLog->save();
             $direction = '/dashboard';
             if ($userGroup->group_id != 1) {
                 $direction = '/saleOrders/index';
             }
             return Redirect::intended($direction);
         }
     } else {
         // if any error send back with message.
         Session::flash('flash_error', 'Invalid username or password!!');
         return Redirect::to('/');
     }
 }