public function postRegistro() { $input = Input::all(); $reglas = array('nombre' => 'required', 'apellido' => 'required', 'celular' => 'required|numeric|unique:users', 'cedula' => 'required|numeric|unique:users', 'email' => 'required|email|unique:users', 'pin' => 'required|numeric|digits_between:0,4', 'password' => 'required|numbers|case_diff|letters|min:6|confirmed', 'password_confirmation' => 'required|min:6'); $validation = Validator::make($input, $reglas); if ($validation->fails()) { return Response::json(['success' => false, 'errors' => $validation->errors()->toArray()]); } try { // se guarda los datos del usuario $user = Sentry::register(array('first_name' => Input::get('nombre'), 'last_name' => Input::get('apellido'), 'email' => Input::get('email'), 'habilitar_pin' => 1, 'celular' => Input::get('celular'), 'cedula' => Input::get('cedula'), 'password' => Input::get('password'), 'pin' => Input::get('pin'), 'porcentaje' => 0.05, 'activated' => true)); $userId = $user->getId(); $token = new Token(); $token->user_id = $userId; $token->api_token = hash('sha256', Str::random(10), false); $token->client = BrowserDetect::toString(); $token->expires_on = Carbon::now()->addMonth()->toDateTimeString(); $token->save(); // Se autentica de una $user_login = Sentry::findUserById($userId); Sentry::login($user_login, false); return Response::json(['success' => true, 'user' => $user_login, 'token' => $token->api_token]); } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) { $error = array('usuario' => 'Email es requerido'); } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) { $error = array('usuario' => 'Password es requerido'); } catch (Cartalyst\Sentry\Users\UserExistsException $e) { $error = array('usuario' => 'El Email ya está registrado'); } return Response::json(['success' => false, 'errors' => $error]); }
public function pushMessage() { if (!Sentry::check()) { return Response::json(array('errCode' => 10, 'message' => '请登录')); } Sentry::login(Sentry::findUserById(5), false); $user = Sentry::getUser(); // $user = User::find(1); $push_status = PushStatus::where('user_id', $user->id)->first(); if (count($push_status) == 0) { $push_status = new PushStatus(); $push_status->user_id = $user->id; $push_status->status = 1; if (!$push_status->save()) { return Response::json(array('errCode' => 1, 'message' => '[数据库错误]开启消息推送失败')); } return Response::json(array('errCode' => 0, 'message' => '开启消息推送')); } if ($push_status->status == 1) { $push_status->status = 0; if (!$push_status->save()) { return Response::json(array('errCode' => 2, 'message' => '[数据库错误]开启消息推送失败')); } return Response::json(array('errCode' => 0, 'message' => '开启消息推送')); } if ($push_status->status == 0) { $push_status->status = 1; if (!$push_status->save()) { return Response::json(array('errCode' => 3, 'message' => '[数据库错误]开启消息推送失败')); } return Response::json(array('errCode' => 0, 'message' => '开启消息推送')); } }
public function post_login() { $errors = new Laravel\Messages(); $input = Input::get(); try { $validator = new Services\Session\Login\Validator($input); $validator->publish(); } catch (ValidateException $errors) { return Redirect::to(URL::to_route('session.login'))->with_input()->with_errors($errors->get()); } try { $valid_login = Sentry::login(Input::get('email'), Input::get('password'), Input::get('remember-me')); if ($valid_login) { $url = null; if (Session::has('pre_login_url')) { $url = Session::get('pre_login_url'); Session::forget('pre_login_url'); } else { $url = URL::to_route('dashboard.profile'); } return Redirect::to($url); } else { $errors->add('errors', __('application.invalid_login')); return Redirect::to(URL::to_route('session.login'))->with_input()->with_errors($errors); } } catch (Sentry\SentryException $e) { $errors->add('errors', $e->getMessage()); return Redirect::to(URL::to_route('session.login'))->with_input()->with_errors($errors); } }
public function loginByToken($token = '') { if ($token) { $token = base64_decode($token); if (User::where('emf_token', '=', $token)->count()) { $user = User::where('emf_token', '=', $token)->first(); if (is_null($user->last_login)) { $start_page = 'walkthrough'; $maildata = new stdClass(); $maildata->user = $user->toArray(); Mail::later(8, 'emails.emf.welcome', (array) $maildata, function ($message) use($user) { $message->to($user->email, $user->first_name && $user->last_name ? $user->first_name . ' ' . $user->last_name : null)->subject('Welcome!'); }); } else { $start_page = 'dashboard'; } $sentry_user = Sentry::findUserById($user->id); Sentry::login($sentry_user, false); $user->password = md5(uniqid(mt_rand(), true)); $user->emf_token = null; $user->updated_at = time(); if ($user->save()) { Log::info('loginByToken() User information was updated.'); } else { Log::info('loginByToken() User information was not updated!'); } return Redirect::route($start_page, array('lang' => App::getLocale())); } else { return Redirect::route('login', array('lang' => App::getLocale())); } } else { return Redirect::route('login', array('lang' => App::getLocale())); } }
/** * User login * * @access public * @return void */ public function action_login() { if ($this->check_logged_type() == 'guest') { \Sentry::logout(); } if (!(\Sentry::check() && !\Sentry::user()->is_admin())) { \View::set_global('title', 'Login'); if (\Input::post('login')) { $val = \User\Controller_Validate::forge('login'); if ($val->run()) { try { if (\Sentry::user_exists(\Input::param('identity')) && !\Sentry::user(\Input::param('identity'))->is_admin()) { // check the credentials. $valid_login = \Sentry::login(\Input::param('identity'), \Input::param('password'), true); if ($valid_login) { if ($this->check_logged_type() == 'guest') { \Messages::info('You cannot log on to with a guest account.'); \Response::redirect(\Uri::front_create('user/account/login')); } \Messages::success('You have logged in successfully'); // \Response::redirect(\Input::referrer(\Uri::front_create('user/account/dashboard'))); \Response::redirect(\Uri::front_create('user/account/dashboard')); } else { \Messages::error('Email and/or password is incorrect'); } } else { \Messages::error('Email and/or password is incorrect'); } } catch (\Sentry\SentryAuthException $e) { // show validation errors //\Messages::error('<h4>There was an error while trying to login</h4>'); $errors = $e->getMessage(); \Messages::error($errors); } catch (\Sentry\SentryException $e) { // show validation errors //\Messages::error('<h4>There was an error while trying to login</h4>'); $errors = $e->getMessage(); \Messages::error($errors); } } else { if ($val->error() != array()) { // show validation errors foreach ($val->error() as $e) { \Messages::error($e->get_message()); } } } } if (\Input::is_ajax()) { echo \Theme::instance()->view($this->view_dir . 'login'); } else { \Theme::instance()->set_partial('content', $this->view_dir . 'single_login'); } } else { //Keep existing messages \Messages::instance()->shutdown(); \Response::redirect(\Uri::front_create('/')); } }
public function action_logout() { if (Sentry::login()) { Session::set_flash('success', 'successfuly logged out'); Sentry::logout(); } else { Session::set_flash('warning', 'You\'re not logged in'); Response::redirect(''); } }
public function testLogoutDestroysSession() { $user = $this->getAdminUser(); Sentry::login($user); // Assert the user was logged in $this->assertTrue(Auth::check()); $this->client->request('GET', '/admin/logout'); $this->assertRedirectedTo('admin/login'); // Assert use is now logged out $this->assertFalse(Auth::check()); }
public function postUlogin() { $_user = json_decode(file_get_contents('http://ulogin.ru/token.php?token=' . Input::get('token') . '&host=' . $_SERVER['HTTP_HOST']), true); //$user['network'] - соц. сеть, через которую авторизовался пользователь //$user['identity'] - уникальная строка определяющая конкретного пользователя соц. сети //$user['first_name'] - имя пользователя //$user['last_name'] - фамилия пользователя $validate = Validator::make([], []); if (isset($_user['error'])) { $validate->errors()->add('error', trans('larulogin::larulogin.' . $_user['error'])); return Response::make(View::make(Config::get('larulogin::views.error'), ['errors' => $validate->errors()]), 401); } // Check exist user $check = Ulogin::where('identity', '=', $_user['identity'])->first(); if ($check) { Auth::loginUsingId($check->user_id, true); if (class_exists('Sentry')) { $authSentry = Sentry::findUserById($check->user_id); Sentry::login($authSentry, true); } return Redirect::to('/'); } $rules = array('network' => 'required|max:255', 'identity' => 'required|max:255|unique:ulogin', 'email' => 'required|unique:ulogin|unique:users'); $messages = array('email.unique' => trans('larulogin::larulogin.email_already_registered')); $validate = Validator::make($_user, $rules, $messages); if ($validate->passes()) { $password = str_random(8); $user = Sentry::createUser(array('first_name' => $_user['first_name'], 'last_name' => $_user['last_name'], 'email' => $_user['email'], 'password' => $password, 'activated' => TRUE)); foreach (Config::get('larulogin::add_to_groups') as $group_name) { $user->addGroup(Sentry::findGroupByName($group_name)); } $ulogin = new Ulogin(); $ulogin->user_id = $user->id; $ulogin->network = $_user['network']; $ulogin->identity = $_user['identity']; $ulogin->email = $_user['email']; $ulogin->first_name = $_user['first_name']; $ulogin->last_name = $_user['last_name']; $ulogin->photo = $_user['photo']; $ulogin->photo_big = $_user['photo_big']; $ulogin->profile = $_user['profile']; $ulogin->access_token = isset($_user['access_token']) ? $_user['access_token'] : ''; $ulogin->country = isset($_user['country']) ? $_user['country'] : ''; $ulogin->city = isset($_user['city']) ? $_user['city'] : ''; $ulogin->save(); $authClassic = Auth::loginUsingId($user->id); if (class_exists('Sentry')) { $authSentry = Sentry::authenticate(array('email' => $_user['email'], 'password' => $password), true); } return Redirect::to('/'); } else { return Response::make(View::make(Config::get('larulogin::views.error'), array('errors' => $validate->errors())), 401); } }
public function testLogoutRouteLogsOutAndRedirects() { $user = $this->factory->create('user'); Sentry::login($user); // Check the user is logged in $this->assertTrue(Auth::check()); // Check the log out action redirects $this->client->request('GET', URL::action('AuthController@getLogout')); $this->assertRedirectedTo('/'); // Check the sue is now logged out $this->assertFalse(Auth::check()); }
/** * * * @return void */ public function callback() { $config = Config::get('opauth'); $Opauth = new Opauth($config, FALSE); if (!session_id()) { session_start(); } $response = isset($_SESSION['opauth']) ? $_SESSION['opauth'] : array(); $err_msg = null; unset($_SESSION['opauth']); if (array_key_exists('error', $response)) { $err_msg = 'Authentication error:Opauth returns error auth response.'; } else { if (empty($response['auth']) || empty($response['timestamp']) || empty($response['signature']) || empty($response['auth']['provider']) || empty($response['auth']['uid'])) { $err_msg = 'Invalid auth response: Missing key auth response components.'; } elseif (!$Opauth->validate(sha1(print_r($response['auth'], true)), $response['timestamp'], $response['signature'], $reason)) { $err_msg = 'Invalid auth response: ' . $reason; } } if ($err_msg) { return Redirect::to('account/login')->with('error', $err_msg); } else { $email = $response['auth']['info']['email']; $authentication = new Authentication(); $authentication->provider = $response['auth']['provider']; $authentication->provider_uid = $response['auth']['uid']; $authentication_exist = Authentication::where('provider', $authentication->provider)->where('provider_uid', '=', $authentication->provider_uid)->first(); if (!$authentication_exist) { if (Sentry::check()) { $user = Sentry::getUser(); $authentication->user_id = $user->id; } else { try { $user = Sentry::getUserProvider()->findByLogin($email); } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { $user = Sentry::register(array('first_name' => $response['auth']['info']['first_name'], 'last_name' => $response['auth']['info']['last_name'], 'email' => $email, 'password' => Str::random(14)), TRUE); } $authentication->user_id = $user->id; } $authentication->save(); } else { $user = Sentry::getUserProvider()->findById($authentication_exist->user_id); Sentry::login($user); Session::put('user_image', $response['auth']['info']['image']); return Redirect::to('/'); } } }
public function askPermission() { $provider = new League\OAuth2\Client\Provider\Facebook(array('clientId' => '372319239612356', 'clientSecret' => '8c78a15dfaa0bf16a81191b68ec89638', 'redirectUri' => 'http://www.subbly.dev/auth')); if (!isset($_GET['code'])) { // If we don't have an authorization code then get one header('Location: ' . $provider->getAuthorizationUrl()); exit; } else { // Try to get an access token (using the authorization code grant) $token = $provider->getAccessToken('authorization_code', ['code' => $_GET['code']]); // Optional: Now you have a token you can look up a users profile data try { // We got an access token, let's now get the user's details $userDetails = $provider->getUserDetails($token); // Use these details to create a new profile printf('Hello %s!', $userDetails->firstName); } catch (Exception $e) { // Failed to get user details exit('Oh dear...'); } try { // Find the user using the user id $user = Sentry::findUserByLogin($userDetails->email); // Log the user in Sentry::login($user, false); // return Redirect::route('home'); } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { // Register the user $user = Sentry::register(array('activated' => 1, 'email' => $userDetails->email, 'password' => Hash::make(uniqid(time())), 'first_name' => $userDetails->firstName)); // $usergroup = Sentry::getGroupProvider()->findById(2); // $user->addGroup($usergroup); Sentry::login($user, false); // return Redirect::route('account'); } Debugbar::info($userDetails); Debugbar::info($user); // exit; // Use this to interact with an API on the users behalf echo $token->accessToken; // Use this to get a new access token if the old one expires echo $token->refreshToken; // Number of seconds until the access token will expire, and need refreshing echo $token->expires; } }
public function storeUserData() { if (Sentry::check()) { return Response::json(array('errCode' => 0, 'message' => '已登录', 'user' => Sentry::getUser())); } // Log::info(Input::get('data')); $data = json_decode(Input::get('data')); // return Input::get('data'); $user = User::where('unionid', '=', $data->unionid)->first(); if (!isset($user)) { // try{ $client_user = Sentry::createUser(array('username' => $data->nickname, 'avatar' => $data->headimgurl, 'gender' => $data->sex, 'email' => $data->unionid, 'password' => $data->unionid, 'openid' => $data->openid, 'unionid' => $data->unionid, 'activated' => '1')); // } // catch(Cartalyst\Sentry\Users\PasswordRequiredException $e) // { // return View::make('errors.missing'); // } // catch(Cartalyst\Sentry\Users\UserExistsException $e) // { // return View::make('errors.missing'); // } // try{ $user = Sentry::findUserById($client_user->id); Sentry::login($user, false); // } // catch(Cartalyst\Sentry\Users\LoginRequiredException $e) // { // return View::make('errors.missing'); // } // catch(Cartalyst\Sentry\Users\UserNotFoundException $e) // { // return View::make('errors.missing'); // } // catch(Cartalyst\Sentry\Users\UserNotActivatedException $e) // { // return View::make('errors.missing') // } return Response::json(array('errCode' => 0, 'message' => '返回参数', 'user' => $user)); } $user = Sentry::findUserById($user->id); Sentry::login($user, false); return Response::json(array('errCode' => 0, 'message' => '返回参数', 'user' => $user)); }
public function loginGithub() { $code = Input::get('code'); $email = Input::get('email'); $github = OAuth::consumer('GitHub'); if (!empty($email)) { $user = User::where('email', '=', $email)->first(); if (isset($user)) { Session::flash('warning', trans('user.register.social.already-exists')); return Redirect::route('user.register'); } $user = Sentry::createUser(array('email' => $email, 'password' => md5(time() . uniqid()), 'activated' => true)); UserGitHub::create(array('user_id' => $user->id, 'access_token' => Input::get('access_token'), 'refresh_token' => !empty(Input::get('refresh_token')) ? Input::get('refresh_token') : null, 'end_of_life' => !empty(Input::get('end_of_life')) ? Input::get('end_of_life') : null)); $user = Sentry::findUserByLogin($user->email); Sentry::login($user, false); Session::flash('success', trans('user.register.social.success')); return Redirect::route('home'); } elseif (empty($code)) { $url = $github->getAuthorizationUri(array('state' => md5(time() . uniqid()), 'redirect_uri' => URL::route('user.login.github'))); return Response::make()->header('Location', (string) $url); } else { $token = $github->requestAccessToken($code); $emails = json_decode($github->request('/user/emails'), true); if (!is_array($emails) || count($emails) === 0) { Session::flash('error', trans('user.register.social.no-emails')); return Redirect::route('user.register'); } if (count($emails) <= 1) { $user = User::where('email', '=', $emails[0])->first(); if (isset($user)) { Session::flash('warning', trans('user.register.social.already-exists')); return Redirect::route('user.register'); } $user = Sentry::createUser(array('email' => $emails[0], 'password' => md5(time() . uniqid()), 'activated' => true)); UserGitHub::create(array('user_id' => $user->id, 'access_token' => $token->getAccessToken(), 'refresh_token' => !empty($token->getRefreshToken()) ? $token->getRefreshToken() : null, 'end_of_life' => !empty($token->getEndOfLife()) ? $token->getEndOfLife() : null)); Sentry::login($user, false); Session::flash('success', trans('user.register.social.success')); return Redirect::route('home'); } return View::make('user.social', array('emails' => $emails, 'token' => $token)); } }
public function execLogin() { $validation_rule = array('email' => 'required|email', 'password' => 'required'); $validator = Validator::make(Input::all(), $validation_rule); if ($validator->fails()) { return Redirect::back()->withInput()->withErrors($validator); } try { $user = Sentry::authenticate(Input::only('email', 'password'), true); Sentry::login($user, true); return Redirect::route('employees.index'); } catch (Cartalyst\Sentry\Throttling\UserSuspendedException $e) { $this->messageBag->add('all', Lang::get('auth/message.account_suspended')); } catch (Cartalyst\Sentry\Throttling\UserBannedException $e) { $this->messageBag->add('all', Lang::get('auth/message.account_banned')); } catch (Exception $e) { $this->messageBag->add('all', Lang::get('auth/message.login.error')); } return Redirect::back()->withInput()->withErrors($this->messageBag); }
/** * The module index * * @return Response */ public function action_index() { \View::set_global('full_page', true); $this->data['title'] = 'Login'; // create the form fieldset, do not add an {open}, a closing ul and a {close}, we have a custom form layout! $fieldset = \Fieldset::forge('login'); $fieldset->add('username', 'Username', array('maxlength' => 50), array(array('required')))->add('password', 'Password', array('type' => 'password', 'maxlength' => 255), array(array('required'), array('min_length', 8))); // was the login form posted? if (\Input::post()) { // run the form validation if (!$fieldset->validation()->run()) { // set any error messages we need to display foreach ($fieldset->validation()->error() as $error) { \Messages::error($error); } } else { try { if (\Sentry::user(\Input::param('username'))->is_admin()) { // check the credentials. $valid_login = \Sentry::login(\Input::param('username'), \Input::param('password'), true); if ($valid_login) { \Messages::success('You have logged in successfully'); if (\Session::get('redirect_to')) { $redirect = \Session::get('redirect_to'); \Session::delete('redirect_to'); } \Response::redirect(isset($redirect) ? $redirect : 'admin'); } else { \Messages::error('Username and/or password is incorrect'); } } else { \Messages::error('Username and/or password is incorrect'); } } catch (\SentryAuthException $e) { $errors = $e->getMessage(); \Messages::error($errors); } } } \Theme::instance()->set_partial('content', 'views/login')->set('fieldset', $fieldset, false); }
/** * Do login * * @return void */ public function post_login() { // do valiation $rules = array('email' => 'required|email', 'password' => 'required'); $input = Input::get(); $validation = Validator::make($input, $rules); if ($validation->fails()) { return Redirect::to('user/login')->with_input()->with_errors($validation); } try { $valid_login = Sentry::login(Input::get('email'), Input::get('password'), Input::get('remember')); if ($valid_login) { return Redirect::to('member/account'); } else { $data['errors'] = "Invalid login!"; } } catch (Sentry\SentryException $e) { $data['errors'] = $e->getMessage(); } return Redirect::to('user/login')->with_input()->with('errors', $data['errors']); }
/** * Execute the console command. * * @return mixed */ public function fire() { ini_set('max_execution_time', 999999999); $this->resetearBD(); DB::setDefaultConnection('migracion_sasyc'); //Se inicia sesion, es requerido en algunos eventos.. Sentry::login(Sentry::findUserById(1)); $this->cargarTablaNivelInstruccion(); $this->cargarTablaParentescos('personas_sasyc'); $this->cargarTablaParentescos('personas_familia'); $this->migrarPersonas(); /*$this->migrarFamiliares(); $this->migrarRequerimientos(); $this->migrarAreas(); $this->migrarRecaudos(); $this->migrarRecepciones(); $this->migrarSolicitudes(); $this->migrarInformeSocioEconomico(); $this->migrarBitacora(); $this->migrarRecaudosSolicitud(); $this->migrarPresupuestos();*/ }
public function post_login() { $data = Input::all(); $rememberme = isset($data['inputRememberMe']) ? true : false; try { if (Sentry::login($data['inputMail'], $data['inputPassword'], $rememberme)) { if (Session::has('pre_login_url')) { $url = Session::get('pre_login_url'); Session::forget('pre_login_url'); return Redirect::to($url); } else { return Redirect::home(); } } else { Session::flash('login_errors', ''); return View::make('user.login'); } } catch (Sentry\SentryException $e) { $errors = $e->getMessage(); Session::flash('login_errors', $errors); return View::make('user.login'); } }
public function postLogin() { $first = Session::get('first'); if ($first == 1) { $route = 'setting'; } else { $route = 'send-notif'; } $validation = array('email' => 'required|email', 'password' => 'required|min:3'); $validator = Validator::make(Input::all(), $validation); if ($validator->fails()) { return Redirect::to('/')->withInput(Input::except('password'))->withErrors($validator); } try { // Login credentials $credentials = array('email' => Input::get('email'), 'password' => Input::get('password')); // Authenticate the user $user = Sentry::authenticate($credentials, false); // Log the user in Sentry::login($user, false); return Redirect::to($route); } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) { return Redirect::to('login')->withInput()->with('msg', 'Login field is required.'); } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) { return Redirect::to('login')->withInput()->with('msg', 'Password field is required.'); } catch (Cartalyst\Sentry\Users\WrongPasswordException $e) { return Redirect::to('login')->withInput()->with('msg', 'Wrong password, try again.'); } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { return Redirect::to('login')->withInput()->with('msg', 'User was not found.'); } catch (Cartalyst\Sentry\Users\UserNotActivatedException $e) { return Redirect::to('login')->withInput()->with('msg', 'User is not activated.'); } catch (Cartalyst\Sentry\Throttling\UserSuspendedException $e) { return Redirect::to('login')->withInput()->with('msg', 'User is suspended.'); } catch (Cartalyst\Sentry\Throttling\UserBannedException $e) { return Redirect::to('login')->withInput()->with('msg', 'User is banned.'); } }
public function isEmailActive() { $token = Input::get('token'); $user = Cache::get($token); if (!isset($user)) { //登录后发邮件去邮箱验证邮箱 return View::make('errors.re-send'); } $status = User::find($user->user_id)->status; //点击一次成功后不能再次使用 if ($status != 10) { return View::make('errors.re-send'); } if (Sentry::check()) { //将状态信息改成未填写登记信息 $user->status = 11; $user->save(); } else { Sentry::login($user, false); $user->status = 11; $user->save(); } return View::make('pages.register-b.reg-info'); }
public function postLogin() { $credentials = array('email' => Input::get('email'), 'password' => Input::get('password')); try { $user = Sentry::authenticate($credentials, false); if ($user) { if (Input::get('remember') == 'true') { Sentry::loginAndRemember($user); } } } catch (\Exception $e) { return Redirect::route('home'); // View::make('hello')->withErrors(array('login' => $e->getMessage()));; } try { Sentry::login($user, false); } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) { echo 'Login field is required.'; } catch (Cartalyst\Sentry\Users\UserNotActivatedException $e) { echo 'User not activated.'; } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { echo 'User not found.'; } }
public function action_login() { $redirect = Session::get('redirect'); $vars = array('email' => '*****@*****.**', 'password' => '123456', 'username' => 'jonathan', 'metadata' => array('first_name' => 'jonathan', 'last_name' => 'de montalembert', 'department' => 'test')); // $user_id = Sentry::user()->create($vars, true); if (Sentry::check()) { Response::redirect($redirect); } $this->template = \View::forge('login'); if (Input::post()) { if (Sentry::user_exists(Input::post('username'))) { // User exists if (Sentry::attempts()->get_limit() > Sentry::attempts(Input::post('username'))->get()) { // max attempts not reached $valid_login = Sentry::login(Input::post('username'), Input::post('password')); if ($valid_login) { Session::set_flash('success', 'Welcome back ' . ucwords(Input::post('username'))); Response::redirect($redirect); } else { $data['username'] = Input::post('username'); $data['password'] = Input::post('password'); Session::set_flash('error', 'Username OR/AND Password incorrects. You tried ' . Sentry::attempts(Input::post('username'))->get() . '/' . Sentry::attempts()->get_limit()); } } else { // max attempts reached Session::set_flash('error', 'You\'ve reached your max attempts and will have to wait for ' . Sentry::attempts(Input::post('username'))->get_time() . ' minutes'); } } else { // user do not exists Session::set_flash('error', 'User do not exists'); } } $this->template->title = $data['title'] = 'Welcome to IKON backoffice'; $this->template->custom_class = 'special_page'; $this->template->content = View::forge('welcome/login', $data); }
public function showCabinet() { $user = Sentry::getUser(); if (!$user) { return Redirect::to('login'); } Sentry::login($user); $results = DB::table('check_logs')->where('id_user', Sentry::getUser()->id)->get(); foreach ($results as $key => $value) { $results[$key]['log'] = json_decode($value['log'], true); } return View::make('user.cabinet', compact('results', 'user'))->render(); }
/** * Registers a user into system */ public function registerAction() { //tab we are on $this->view->login_tab = "register_form"; //if we are not a post just render view if ($this->request->isPost() == false) { return $this->view->render('login', 'index'); } //preset our error if any $errors = array(); //get our posts required $email = $this->request->getPost("email", null, false); if ($email == false) { $errors[] = "Missing email address"; } $password = $this->request->getPost("password", null, false); if ($password == false) { $errors[] = "Missing password"; } $confirm = $this->request->getPost("confirm", null, false); if ($confirm == false) { $errors[] = "Missing confirm password"; } if ($confirm != false && $confirm != $password) { $errors[] = "Passwords don't match"; } //check any errors $errors = $this->errorCheck($errors); if ($errors) { return $errors; } /** safe to register user below this point **/ try { // Let's register a user. $user = Sentry::register(array('email' => $email, 'password' => $password, 'activated' => true)); // Send activation code to the user so he can activate the account } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) { $errors[] = 'Login field is required.'; } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) { $errors[] = 'Password field is required.'; } catch (Cartalyst\Sentry\Users\UserExistsException $e) { $errors[] = 'User with this login already exists.'; } //check any errors $errors = $this->errorCheck($errors); if ($errors) { return $errors; } // Authenticate the user and log them in Sentry::login($user, false); return $this->response->redirect('index'); }
return Redirect::guest('user/login'); } } else { if (!Sentry::check()) { $user = Sentry::findUserById(Session::get('user.id')); Sentry::login($user, false); } } }); Route::filter('auth.doc_is_in', function () { if (!Session::has('user.id')) { return Redirect::guest('doc/login'); } else { if (!Sentry::check()) { $user = Sentry::findUserById(Session::get('user.id')); Sentry::login($user, false); } } }); Route::filter('weixin', function () { $signature = Input::get('signature'); $timestamp = Input::get('timestamp'); $nonce = Input::get('nonce'); $tmpArr = array('ziruikeji', $timestamp, $nonce); sort($tmpArr, SORT_STRING); $tmpStr = implode($tmpArr); $tmpStr = sha1($tmpStr); if ($tmpStr != $signature) { return 'Fail'; } //return $tmpStr == $signature;
public function createOAuthProfile($userProfile) { if (isset($userProfile->username)) { $username = strlen($userProfile->username) > 0 ? $userProfile->username : ""; } if (isset($userProfile->screen_name)) { $username = strlen($userProfile->screen_name) > 0 ? $userProfile->screen_name : ""; } if (isset($userProfile->displayName)) { $username = strlen($userProfile->displayName) > 0 ? $userProfile->displayName : ""; } $email = strlen($userProfile->email) > 0 ? $userProfile->email : ""; $email = strlen($userProfile->emailVerified) > 0 ? $userProfile->emailVerified : ""; $password = $this->generatePassword(); if (Profile::where('email', $email)->count() <= 0) { $user = Sentry::register(array('email' => $email, 'password' => $password), true); try { $user_group = Sentry::findGroupById(1); } catch (Cartalyst\Sentry\Groups\GroupNotFoundException $e) { $this->createGroup('users'); $this->createGroup('admin'); $user_group = Sentry::findGroupById(1); } $user->addGroup($user_group); $profile = new Profile(); $profile->user_id = $user->getId(); $profile->email = $email; $profile->username = $username; $profile->save(); } //Login user //Try to authenticate user try { $user = Sentry::findUserByLogin($email); $throttle = Sentry::getThrottleProvider()->findByUserId($user->id); $throttle->check(); //Authenticate user $credentials = array('email' => $email, 'password' => Input::get('password')); Sentry::login($user, false); //At this point we may get many exceptions lets handle all user management and throttle exceptions } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) { Session::flash('error_msg', 'Login field is required.'); return Redirect::to('/login'); } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) { Session::flash('error_msg', 'Password field is required.'); return Redirect::to('/login'); } catch (Cartalyst\Sentry\Users\WrongPasswordException $e) { Session::flash('error_msg', 'Wrong password, try again.'); return Redirect::to('/login'); } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { Session::flash('error_msg', 'User was not found.'); return Redirect::to('/login'); } catch (Cartalyst\Sentry\Users\UserNotActivatedException $e) { Session::flash('error_msg', 'User is not activated.'); return Redirect::to('/login'); } catch (Cartalyst\Sentry\Throttling\UserSuspendedException $e) { Session::flash('error_msg', 'User is suspended '); return Redirect::to('/login'); } catch (Cartalyst\Sentry\Throttling\UserBannedException $e) { Session::flash('error_msg', 'User is banned.'); return Redirect::to('/login'); } }
public function loginWithGoogle() { // get data from input $code = Input::get('code'); // get google service $googleService = OAuth::consumer('Google'); // check if code is valid // if code is provided get user data and sign in if (!empty($code)) { // This was a callback request from google, get the token $token = $googleService->requestAccessToken($code); // Send a request with it $result = json_decode($googleService->request('https://www.googleapis.com/oauth2/v1/userinfo'), true); if (!empty($token)) { try { // Find the user using the user id $user = Sentry::findUserByLogin($result['email']); // Log the user in Sentry::login($user, false); return Redirect::route('home'); } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { // Register the user $user = Sentry::register(array('activated' => 1, 'email' => $result['email'], 'password' => Hash::make(uniqid(time())), 'first_name' => $result['name'], 'avatar' => $result['picture'], 'country' => !empty($result['location']) ? $result['location'] : false)); $usergroup = Sentry::getGroupProvider()->findById(2); $user->addGroup($usergroup); Sentry::login($user, false); return Redirect::route('account'); } } } else { // get googleService authorization $url = $googleService->getAuthorizationUri(); // return to facebook login url return Redirect::to((string) $url); } }
public function accessToken() { if (Sentry::check()) { return Redirect::to('/pc_home')->with(array('user' => Sentry::getUser())); } // Session::put('code', Input::get('code')); $code = Input::get('code'); $weixin_data = $this->getAccessTokenByCode($code); // var_dump($weixin_data); $access_token = $weixin_data['access_token']; $refresh_token = $weixin_data['refresh_token']; $open_id = $weixin_data['openid']; $unionid = $weixin_data['unionid']; $user = $this->getUserInfoByAuth($access_token, $open_id); $unionid_user = User::where('unionid', '=', $unionid)->first(); if (!isset($unionid_user)) { // try{ $client_user = Sentry::createUser(array('username' => $user['nickname'], 'avatar' => $user['headimgurl'], 'gender' => $user['sex'], 'email' => $user['unionid'], 'password' => $user['unionid'], 'openid' => $user['openid'], 'unionid' => $user['unionid'], 'activated' => '1')); // } // catch(Cartalyst\Sentry\Users\PasswordRequiredException $e) // { // return View::make('errors.missing'); // } // catch(Cartalyst\Sentry\Users\UserExistsException $e) // { // return View::make('errors.missing'); // } // try{ $user = Sentry::findUserById($client_user->id); Sentry::login($user, false); // } // catch(Cartalyst\Sentry\Users\LoginRequiredException $e) // { // return View::make('errors.missing'); // } // catch(Cartalyst\Sentry\Users\UserNotFoundException $e) // { // return View::make('errors.missing'); // } // catch(Cartalyst\Sentry\Users\UserNotActivatedException $e) // { // return View::make('errors.missing') // } return Redirect::to('/pc_home')->with(array('user' => $user)); } $user = Sentry::findUserById($unionid_user->id); Sentry::login($user, false); return Redirect::to('/pc_home')->with(array('user' => $user)); }
public function create_user() { // Get groups $groups = \Sentry::group()->all('front'); if (\Input::post()) { // Get POST values $insert = \Input::post(); $register_type = 'register'; if (\Input::post('register')) { $register_type = $insert['register']; } $ship_to = 'billing'; if ($insert['ship'] == 'other') { $ship_to = 'shipping'; } $val = \User\Controller_Validate::forge($register_type == 'register' ? 'create' : 'guest', false, $ship_to == 'shipping' ? 'shipping' : false); if ($val->run()) { array_walk($insert, create_function('&$val', '$val = trim($val);')); try { // Generate random username $email = $insert['email']; $user_group = 3; if ($register_type == 'guest') { $username = '******' . \Str::random('numeric', 16); $insert['guest'] = 1; $random_password = '******' . \Str::random(unique); $password = $random_password; } else { $username = $email; $insert['guest'] = 0; $password = $insert['password']; } unset($insert['email'], $insert['password'], $insert['confirm_password'], $insert['user_group'], $insert['details'], $insert['save'], $insert['update']); $only_billing = array('email'); $billing_data = \Arr::filter_prefixed($insert, "billing_"); // Set shipping data to be same as billing by default if ($ship_to_billing) { foreach ($billing_data as $key => $value) { if (!in_array($key, $only_billing)) { $insert['shipping_' . $key] = $value; } } } $metadata = \Arr::remove_prefixed($insert, "billing_") + $billing_data; $table = \DB::table_prefix('users_metadata'); $columns = \DB::list_columns($table); $insert = array_intersect_key($metadata, $columns); // create the user - no activation required $vars = array('username' => $username, 'email' => $email, 'password' => $password, 'metadata' => $insert); $user_id = \Sentry::user()->create($vars); $user = \Sentry::user($user_id); // Add user to 'customer' group (id = 3) if ($user_id and $user->add_to_group($user_group)) { if ($register_type == 'account') { \Messages::success('User successfully created.'); } if ($register_type == 'guest') { \Messages::success('You register as a guest.'); } $login_column = \Config::get('sentry.login_column', 'email'); if (\Sentry::login(${$login_column}, $password, true)) { \Response::redirect(\Uri::create('order/checkout/cost')); } else { if ($register_type == 'account') { \Messages::error('There was an error while trying to create account. Please try to create new account.'); } if ($register_type == 'guest') { \Messages::error('There was an error. Please try to login with your account details.'); } } } else { // show validation errors \Messages::error('There was an error while trying to create account.'); } } catch (\Sentry\SentryException $e) { // show validation errors \Messages::error('There was an error while trying to create user.'); $errors = $e->getMessage(); \Messages::error($errors); } } else { if ($val->error() != array()) { // show validation errors \Messages::error('There was an error while trying to create user.'); foreach ($val->error() as $e) { \Messages::error($e->get_message()); } } } } }
if ($email = $request->getUser() && ($password = $request->getPassword())) { $credentials = array('email' => $request->getUser(), 'password' => $request->getPassword()); $auth = App::make('auth'); if (Auth::once($credentials)) { $authenticated = true; if (!Auth::user()->tokens()->where('client', BrowserDetect::toString())->first()) { $token = []; $token['api_token'] = hash('sha256', Str::random(10), false); $token['client'] = BrowserDetect::toString(); $token['expires_on'] = Carbon::now()->addMonth()->toDateTimeString(); Auth::user()->tokens()->save(new Token($token)); } } } if ($payload = $request->header('X-Auth-Token')) { $userModel = Sentry::getUserProvider()->createModel(); $token = Token::valid()->where('api_token', $payload)->where('client', BrowserDetect::toString())->first(); if ($token) { Sentry::login($token->user); $authenticated = true; } } if ($authenticated && !Sentry::check()) { Sentry::login(Auth::user()); } if (!$authenticated) { $response = Response::json(['error' => true, 'message' => 'Not authenticated', 'code' => 401], 401); $response->header('Content-Type', 'application/json'); return $response; } });