Commit dc823c41 by gema

Merge branch 'master' of http://git.setisl.com/inutraliaapp/2018_web_app into gemis_dev

parents 05fdc2f1 69e536ab
...@@ -24,9 +24,9 @@ class Controller_App extends Controller{ ...@@ -24,9 +24,9 @@ class Controller_App extends Controller{
public function before(){ public function before(){
if (! Auth::check() ){ if (!$this->control_time_session()){
Response::redirect("/");
Session::destroy(); Session::destroy();
Response::redirect("/");
} }
Config::load('app', true); Config::load('app', true);
...@@ -34,6 +34,21 @@ class Controller_App extends Controller{ ...@@ -34,6 +34,21 @@ class Controller_App extends Controller{
parent::before(); parent::before();
} }
public function control_time_session(){
if(Session::get('expire_session') === null || Session::get('expire_session') > strtotime(date("Y-m-d H:i:s")) ){
Session::set('expire_session',strtotime(date("Y-m-d H:i:s",strtotime("+1 Hour"))));
return true;
}else{
return false;
}
}
public function post_locale(){ public function post_locale(){
$id = Input::post('id',''); $id = Input::post('id','');
......
...@@ -16,198 +16,154 @@ use Fuel\Core\Log; ...@@ -16,198 +16,154 @@ use Fuel\Core\Log;
use Fuel\Core\Response; use Fuel\Core\Response;
use Fuel\Core\Security; use Fuel\Core\Security;
class Controller_Login_Index extends Controller{ class Controller_Login_Index extends Controller
{
use \Trait_InutraliaWS;
public function get_login() public function get_login()
{ {
// redirects if the user is logged // redirects if the user is logged
if (Auth::check()) { // Si tiene el token auth esta logeado, en el before del controller APP controlamos el tiempo de exipacion de sessión.
// En el Logut tenemos que destruir la sesión.
if (\Session::get('token_auth') !== null) {
$datos = \Config::load('empresa'); $datos = \Config::load('empresa');
Session::set('empresa',$datos); Session::set('empresa', $datos);
return Response::redirect('/dashboard');
}
return Response::redirect('/dashboard'); $view = View::forge('login.twig');
return $view;
} }
$view = View::forge('login.twig'); public function post_login()
return $view; {
}
$datos = \Config::load('empresa');
Session::set('empresa', $datos);
public function post_login() $username = \Input::post('username');
{ $password = \Input::post('password');
$datos = \Config::load('empresa');
Session::set('empresa',$datos);
// performs de validation // performs de validation
if (!Security::check_token()) { if (!Security::check_token()) {
Session::set_flash( Session::set_flash(
'message:error', 'message:error',
'Se perdio la ventana de autenticación, ha pasado demasiado tiempo 'Se perdio la ventana de autenticación, ha pasado demasiado tiempo
inactivo, intentelo de nuevo.' inactivo, intentelo de nuevo.'
); );
Response::redirect('auth/login'); Response::redirect('auth/login');
return null; return null;
} }
$val = Validation::forge(); // seteamos el old input
$val->add('username', 'Correo Electronico') \Session::set_flash('login:username', \Input::post('username'));
->add_rule('required');
$val->add('password', 'Contraseña')
->add_rule('required');
// seteamos el old input $return = (array)$this->ws_user($username,$password);
Session::set_flash('login:username', \Input::post('username'));
if ($val->run()) { if(!isset($return['status'])){
try {
Auth::attempt(
array(
'username' => $val->validated('username'),
'password' => $val->validated('password')
)
);
$usu = array( Response::redirect('/dashboard');
'username' => $val->validated('username'),
'nombre' => $val->validated('password')
);
Session::set('usuario',$usu); return null;
Response::redirect('/dashboard'); }elseif ($return['status'] == "0"){
return null; \Session::set_flash(
'message:error',
$return['error'].' - Error al introducir el nombre de usuario o contraseña'
);
}else{
\Session::set_flash(
'message:error',
'Para entrar en tu cuenta tienes que introducir tu email y contraseña.'
);
}
} catch (UserNotFoundException $e) {
Session::set_flash(
'message:error',
'No es posible entrar, email o contraseña incorrecto'
);
Response::redirect('auth/login');
return null;
}
catch (UserUnverifiedException $e) {
Session::set_flash(
'message:error',
'La cuenta a la que intenta conectarse no esta verificada aún. Inténtelo más tarde.'
);
Response::redirect('auth/login');
return null;
}
catch (UserPasswordIncorrectException $e) {
Session::set_flash(
'message:error',
'No es posible entrar, email o contraseña incorrecto'
);
Response::redirect('auth/login');
return null;
}
catch (UserDisabledException $e) {
Session::set_flash(
'message:error',
'"No es posible acceder a tu cuenta porque está desactivada. Por favor, contacta con nuestro equipo de atención al cliente."'
);
Response::redirect('auth/login'); Response::redirect('auth/login');
return null; return null;
}
} else {
Session::set_flash(
'message:error',
'Para entrar en tu cuenta tienes que introducir tu email y contraseña.'
);
Response::redirect('auth/login');
return null;
} }
}
public function get_logout() public function get_logout()
{ {
Auth::logout(); Auth::logout();
Response::redirect('/'); Response::redirect('/');
} }
public function get_recover(){ public function get_recover()
$view = View::forge('recover.twig'); {
$view = View::forge('recover.twig');
return Response::forge ($view); return Response::forge($view);
} }
public function post_recover() public function post_recover()
{ {
$usuario = Model_Auth_User::query() $usuario = Model_Auth_User::query()
->where('user',Input::Post('username','')) ->where('user', Input::Post('username', ''))
->related('group') ->related('group')
->get_one(); ->get_one();
if(isset($usuario) && $usuario->valid == 1) if (isset($usuario) && $usuario->valid == 1) {
{ $view = \View::forge("emails/pedidos/adminResend");
$view = \View::forge("emails/pedidos/adminResend");
$view->user = $usuario->user; $view->user = $usuario->user;
$view->password = $usuario->password; $view->password = $usuario->password;
$body = $view->render(); $body = $view->render();
$comu_session = Config::get('email'); $comu_session = Config::get('email');
$error = false; $error = false;
//Preparar envio //Preparar envio
try try {
{ $transport = Swift_SmtpTransport::newInstance($comu_session['smtp'], $comu_session['port'], 'tls')
$transport = Swift_SmtpTransport::newInstance($comu_session['smtp'], $comu_session['port'], 'tls') ->setUsername($comu_session['user'])->setPassword($comu_session['password']);
->setUsername($comu_session['user'])->setPassword($comu_session['password']);
$mailer = Swift_Mailer::newInstance($transport); $mailer = Swift_Mailer::newInstance($transport);
} } catch (Exception $e) {
catch(Exception $e) Log::error('Error Enviando correo1 - >' . $e->getMessage());
{ $error = true;
Log::error('Error Enviando correo1 - >'. $e->getMessage()); }//endCatch
$error = true;
}//endCatch
//Enviar Correo //Enviar Correo
if (!$error) if (!$error) {
{ try {
try $message = Swift_Message::newInstance("Recuperación de contraseña")
{ ->setFrom(array($comu_session['emailfrom'] => $comu_session['emailfrom']))
$message = Swift_Message::newInstance("Recuperación de contraseña") ->setBody($body, 'text/html');
->setFrom(array ($comu_session['emailfrom'] => $comu_session['emailfrom']))
->setBody($body, 'text/html');
$message->setTo(array ($comu_session['email'] => $comu_session['email'])); $message->setTo(array($comu_session['email'] => $comu_session['email']));
$mailer->send($message); $mailer->send($message);
} } catch (Exception $e) {
catch(Exception $e) Log::error('Error Enviando corre2 - >' . $e->getMessage());
{ $error = true;
Log::error('Error Enviando corre2 - >'. $e->getMessage()); }//endCatch
$error = true; }//endIf
}//endCatch
}//endIf
if ($error)
{
Session::set_flash('msges.error',array('Error enviando correo.')); //Enviar Notifys!!!
}
else
{
Session::set_flash('msges.ok',array('Correos enviados correctamente.'));
}//endIf
Response::redirect('/');
}
else
{
//notificar Usuario no valido
Response::redirect('recover'); if ($error) {
Session::set_flash('msges.error', array('Error enviando correo.')); //Enviar Notifys!!!
} else {
Session::set_flash('msges.ok', array('Correos enviados correctamente.'));
}//endIf
Response::redirect('/');
} else {
//notificar Usuario no valido
Response::redirect('recover');
}
} }
}
} }
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Villa
* Date: 03/12/2018
* Time: 16:21
*/
trait Trait_InutraliaWS {
public function save_token_credentials ($token_auth){
\Session::set('token_auth',$token_auth);
}
public function get_header(){
return array(
'Content-Type: application/json',
'Accept: application/json',
'Authorization: Basic '. \Session::get('token_auth')
);
}
/**
* Method to make requests to inutralia.
*
* MORE INFO CURL --> http://php.net/manual/es/function.curl-setopt.php
*
* @param $parameter_url
* @param bool $header
* @param int $timeout
* @param bool $httpget
* @param int $return_transfer
* @return mixed
*/
public function request_generic($parameter_url, $header = false, $timeout = 30, $httpget = true, $return_transfer = 1){
$constant = \Config::load('constants');
// La url la obtiene de config dependiendo del entorno.
$process = curl_init($constant[$parameter_url]);
curl_setopt($process, CURLOPT_HTTPHEADER,$this->get_header());
curl_setopt($process, CURLOPT_HEADER, $header);
curl_setopt($process, CURLOPT_TIMEOUT, $timeout);
curl_setopt($process, CURLOPT_HTTPGET , $httpget);
curl_setopt($process, CURLOPT_RETURNTRANSFER, $return_transfer);
$return = curl_exec($process);
curl_close($process);
return $return;
}
/**
*
* User auth basic request for login, save the user token in session for all requests.
*
* @param $user
* @param $password
*/
public function ws_user($user,$password){
$this->save_token_credentials(base64_encode("$user:$password"));
return json_decode($this->request_generic('user'));
}
/**
* Request get profile
*/
public function ws_profile(){
return json_decode($this->request_generic('profile'));
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Villa
* Date: 04/12/2018
* Time: 10:45
*/
/* Structure -- > http://i20.inutralia.com/api/v1/{0}?api-key=7745289b-f09c-4e0b-89d1-bb59c599c85e"
Donde {0} puede ser :
- user -> Method get
- generic( id = null) -> Method get
- article(id = null) -> Method get
- profile -> Method get/put
- menu -> Method get
- options -> Method get
- recipe(id = null) -> Method get
- recipes -> Method get
- trivial -> Method get
- video -> Method get
*/
// Url redirect a DEL SUPER --> "https://delsuper.es/inutralia?ids=";
const DOMAIN = "http://inutralia20back";
const V1 = '/api/v1/';
const APIKEY = "?api-key=7745289b-f09c-4e0b-89d1-bb59c599c85e";
// PARAMETERS
const USER = 'user';
return array(
'user' => DOMAIN.V1.USER.APIKEY,
);
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Villa
* Date: 04/12/2018
* Time: 10:45
*/
/* Structure -- > http://i20.inutralia.com/api/v1/{0}?api-key=7745289b-f09c-4e0b-89d1-bb59c599c85e"
Donde {0} puede ser :
- user -> Method get
- generic( id = null) -> Method get
- article(id = null) -> Method get
- profile -> Method get/put
- menu -> Method get
- options -> Method get
- recipe(id = null) -> Method get
- recipes -> Method get
- trivial -> Method get
- video -> Method get
*/
// Url redirect a DEL SUPER --> "https://delsuper.es/inutralia?ids=";
const DOMAIN = " http://i20.inutralia.com";
const V1 = '/api/v1/';
const APIKEY = "?api-key=7745289b-f09c-4e0b-89d1-bb59c599c85e";
// PARAMETERS
const USER = 'user';
return array(
'user' => DOMAIN.V1.USER.APIKEY,
);
\ No newline at end of file
...@@ -675,3 +675,9 @@ INFO - 2018-11-27 17:11:07 --> Fuel\Core\Request::execute - Setting main Request ...@@ -675,3 +675,9 @@ INFO - 2018-11-27 17:11:07 --> Fuel\Core\Request::execute - Setting main Request
INFO - 2018-11-27 17:11:10 --> Fuel\Core\Request::__construct - Creating a new main Request with URI = "dashboard" INFO - 2018-11-27 17:11:10 --> Fuel\Core\Request::__construct - Creating a new main Request with URI = "dashboard"
INFO - 2018-11-27 17:11:10 --> Fuel\Core\Request::execute - Called INFO - 2018-11-27 17:11:10 --> Fuel\Core\Request::execute - Called
INFO - 2018-11-27 17:11:10 --> Fuel\Core\Request::execute - Setting main Request INFO - 2018-11-27 17:11:10 --> Fuel\Core\Request::execute - Setting main Request
INFO - 2018-11-27 17:36:02 --> Fuel\Core\Request::__construct - Creating a new main Request with URI = ""
INFO - 2018-11-27 17:36:02 --> Fuel\Core\Request::execute - Called
INFO - 2018-11-27 17:36:02 --> Fuel\Core\Request::execute - Setting main Request
INFO - 2018-11-27 17:36:03 --> Fuel\Core\Request::__construct - Creating a new main Request with URI = "assets/img/logos/logo_seti_50x50_black_orange"
INFO - 2018-11-27 17:36:03 --> Fuel\Core\Request::execute - Called
INFO - 2018-11-27 17:36:03 --> Fuel\Core\Request::execute - Setting main Request
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment