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 class constructor * @access public * @throws Exception when user has already been registered */ public function __construct() { if (isset($_SESSION['visitor']) && $_SESSION['visitor'] == "accessed") { throw new Exception("User already registered", 1); } else { $this->dateTime = Carbon::now(); $this->browser = BrowserDetect::browserFamily(); $this->OS = BrowserDetect::osName(); if (BrowserDetect::isMobile()) { $this->deviceType = "mobile"; } elseif (Browser::isTablet()) { $this->deviceType = "tablet"; } elseif (Browser::isDesktop()) { $this->deviceType = "desktop"; } elseif (Browser::isBot()) { $this->deviceType = "bot"; } else { $this->deviceType = "unknown"; } $this->deviceFamily = Broswer::deviceFamily(); $this->deviceModel = Browser::deviceModel(); $this->broadcastAddress = $_SERVER["REMOTE_ADDR"]; $this->model = new AccessModel($this); } }
/** * signin.post * */ public function postSignIn() { try { $credenciales = array('email' => Input::get('email'), 'password' => Input::get('password')); $sentry = Sentry::authenticate($credenciales, false); $user = $this->user->find($sentry->id); if (!$user->tokens()->where('client', BrowserDetect::toString())->first()) { $token = []; $token['api_token'] = hash('sha256', Str::random(10), false); $token['client'] = BrowserDetect::toString(); $token['expires_on'] = 0; $user->tokens()->save(new Token($token)); } if (Sentry::check()) { if ($sentry->hasAnyAccess(['admin'])) { return Redirect::route('admin.dashboard')->with(['message' => $sentry->first_name . ' ' . $sentry->last_name, 'class' => 'info']); } else { if ($sentry->hasAnyAccess(['users'])) { return Redirect::route('users.dashboard')->with(['message' => $sentry->first_name . ' ' . $sentry->last_name, 'class' => 'info']); } } } else { return Redirect::route('home')->withInput(); } } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) { return Redirect::route('signin')->with(['message' => 'Se requiere campo E-Mail', 'class' => 'warning']); } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) { return Redirect::route('signin')->with(['message' => 'Se requiere campo Contraseña.', 'class' => 'warning']); } catch (Cartalyst\Sentry\Users\WrongPasswordException $e) { return Redirect::route('signin')->with(['message' => 'Contraseña incorrecta, vuelva a intentarlo.', 'class' => 'warning']); } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { return Redirect::route('signin')->with(['message' => 'El usuario no se ha encontrado.', 'class' => 'danger']); } catch (Cartalyst\Sentry\Users\UserNotActivatedException $e) { return Redirect::route('signin')->with(['message' => 'El usuario no está activado.', 'class' => 'warning']); } catch (Cartalyst\Sentry\Throttling\UserSuspendedException $e) { return Redirect::route('signin')->with(['message' => 'Usuario está suspendido.', 'class' => 'info']); } catch (Cartalyst\Sentry\Throttling\UserBannedException $e) { return Redirect::route('signin')->with(['message' => 'Usuario está prohibido.', 'class' => 'info']); } }
public function index() { //Limpando a sessão independente do redirecionamento session_destroy(); $this->session->sess_destroy(); // $data = $this->getParametroVisao(); $data['msg'] = $this->getMsg(); $data['abaAtiva'] = ''; $data['abaPage'] = 'login'; if (BrowserDetect::isMobile()) { $data['tema'] = $this->load->setTheme('responsive'); $data["shadowbox"] = 1; $data['page'] = 'login_w/responsive/' . __FUNCTION__; $data["css"] = array("js/bower/bootstrap/dist/css/bootstrap.min.css", "js/bower/metisMenu/dist/metisMenu.min.css"); $data["js"] = array("js/bower/jquery/dist/jquery.min.js", "js/bower/bootstrap/dist/js/bootstrap.min.js", "js/bower/metisMenu/dist/metisMenu.min.js"); } else { $data['page'] = 'default'; $data['tema'] = $this->load->setTheme('default'); } $data['largura_percent'] = 30; $data['margin_top'] = 'margin_top70'; $data['bordasMain'] = false; // Se não for retornado erro de senha, reseta o item 'qtd' if (!isset($_SESSION['erroUsuarioSenha'])) { $_SESSION['erroUsuarioSenha']['qtd'] = 0; } // Se o número de erro de senha for maior ou igual a 3 if ($_SESSION['erroUsuarioSenha']['qtd'] >= 3) { // gera um código randomico de quatro caracteres $_SESSION['erroUsuarioSenha']['codigo'] = Util::getRandomString(4); // chama o helper captcha, seta suas variáveis, cria a imagem e envia a view $this->load->helper('captcha'); $vals = array('word' => $_SESSION['erroUsuarioSenha']['codigo'], 'img_path' => './captcha/', 'img_url' => base_url() . 'captcha/', 'font_path' => './system/fonts/texb.ttf', 'img_width' => '120', 'img_height' => 30, 'expiration' => 1); $cap = create_captcha($vals); $data['captcha'] = $cap['image']; } // Carrega a view $this->load->view($this->load->getUrlTema(), $data); }
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; } });
public function login() { $user = Auth::user(); $token = $user->tokens()->where('client', BrowserDetect::toString())->first(); return $this->respondWithArray(['user' => $user->toArray(), 'token' => $token]); }
/** * Função que verifica se o navegador é mobile ou desktop * @return boolean Retorna TRUE caso seja mobile ou FALSE caso contrario */ public static function isMobile() { $tmp = new BrowserDetect(); return $tmp->getDispositivo() == "Desktop" ? FALSE : TRUE; }
public function getMe() { $user = Sentry::getUser(); $token = $user->tokens()->where('client', BrowserDetect::toString())->first(); return Response::json(array('user' => $user->toArray(), 'token' => $token->toArray())); }
$prop_key = $data_prop . '_' . App::getLocale(); if (is_object($data) && property_exists($data, $prop_key)) { return $data->{$prop_key}; } elseif (is_array($data) && isset($data[$prop_key])) { return $data[$prop_key]; } } }, 'makeAllSides' => function ($template, $context, $args, $source) { $html = '<div class="left-pane side setSize hiddenBackface"></div><div class="right-pane side hiddenBackface setSize"></div><div class="back-pane side setSize hiddenBackface"></div>'; if (BrowserDetect::isIE()) { $html = '<div class="back-pane hiddenBackface side setSize"></div>'; } return $html; }, 'makeSides' => function ($template, $context, $args, $source) { $html = '<div class="left-pane side setSize hiddenBackface"></div><div class="right-pane side setSize hiddenBackface"></div>'; if (BrowserDetect::isIE()) { $html = '<div class="back-pane side setSize"></div>'; } return $html; }, 'include' => function ($template, $context, $args, $source) { $parial = false; $partial_data = array(); if (!empty($args)) { $_args = explode(' ', $args); $partial = array_shift($_args); $partial = trim($partial, " \\'\""); if (!empty($_args)) { foreach ($_args as $arg) { if (strpos($arg, '=')) { $re = '/(\\w+)=["\']([^"\'<>]+)["\']/'; if (preg_match($re, $arg, $m)) {
<?php // all templates View::composer('hbs::*', function ($view) { // add common data $view->with(array('baseUrl' => url(), 'lang' => App::getLocale(), 'ie' => \BrowserDetect::isIE(), 'ie11' => \BrowserDetect::isIEVersion(11))); // get data (assume page) if ($view->offsetExists('data')) { $page = $view->offsetGet('data'); // page name if ($page && is_object($page) && property_exists($page, 'name')) { $view->with('page', $page->name); } } $viewName = $view->offsetExists('viewName') ? $view->offsetGet('viewName') : ''; $view->with('viewName', $viewName); }); // all templates View::composer('hbs::navigation', function ($view) { /* $routes = $view->offsetGet('data'); $data = new stdClass; $data->desktop = $routes[0]; $data->mobile = $routes[1]; $view->with(array( 'data' => $data, )); */ }); // home.hbs View::composer(array('hbs::home', 'hbs::homeIE'), function ($view) {
$blockCSS = false; if (BrowserDetect::browserFamily() == 'Chrome' && (BrowserDetect::isMobile() || BrowserDetect::isTablet())) { switch (str_replace('.css', '', $file = $file->getFilename())) { case 'tablet': $blockCSS = false; break; case 'mobile': $blockCSS = !BrowserDetect::isMobile(); break; case 'noDotNet': case 'small': case 'smallMedium': case 'medium': case 'large': case 'small': $blockCSS = BrowserDetect::browserFamily() != 'Internet Explorer'; break; } } else { //default to desktop view. switch (str_replace('.css', '', $file = $file->getFilename())) { case 'noDotNet': $media = 'screen and (max-width: 350px)'; break; case 'small': $media = 'screen and (max-width: 500px)'; break; case 'smallMedium': $media = 'screen and (min-width: 500px) and (max-width: 650px)'; break; case 'medium':
protected function renderHomePage() { $view_data = array(); // -------------------------------------- $meta_data = $this->setMetaData(); $view_data = array_merge($view_data, $meta_data); // navigation // -------------------------------------- $view_data['navigation'] = $this->renderNavigation(); // -------------------------------------- $template_data = $this->setPageData(); // page template (handlebars) $ie = \BrowserDetect::isIE(); $isMobile = \BrowserDetect::isMobile(); //$tmpl = ($ie || $isMobile) ? 'hbs::homeIE' : 'hbs::home'; $tmpl = 'hbs::home'; $content = View::make($tmpl, $template_data); $view_data['content'] = $content; return View::make('layouts.application', $view_data); }