PageRenderTime 23ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/application/controllers/Home.php

https://gitlab.com/narugamy/corazon
PHP | 195 lines | 179 code | 16 blank | 0 comment | 23 complexity | 1f2cc99373443dec04abb5428ab2d92f MD5 | raw file
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. class Home extends CI_Controller {
  4. private $perfil;
  5. public function __construct()
  6. {
  7. parent::__construct();
  8. $this->load->model('Modeluser');
  9. $this->load->model('Modeltype');
  10. $this->perfil=$this->session->userdata('Perfil');
  11. }
  12. function GeneraPass(){
  13. $cadena = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
  14. $longitudCadena=strlen($cadena);
  15. $pass = "";
  16. $longitudPass=15;
  17. for($i=1 ; $i<=$longitudPass ; $i++){
  18. $pos=rand(0,$longitudCadena-1);
  19. $pass .= substr($cadena,$pos,1);
  20. }
  21. return $pass;
  22. }
  23. public function Generar(){
  24. if($this->session->userdata('Perfil')=='vista'){
  25. $this->Recupera();
  26. $error=array('exito'=>false,'email'=>'');
  27. $er=array('email'=>'');
  28. $email=$this->input->post('email');
  29. if($this->form_validation->run() == FALSE){
  30. $er['email']=form_error('email');
  31. }else{
  32. $dato=$this->Modeluser->get(array('email'=>$email));
  33. if(empty($dato->email)){
  34. $er['email']="El correo no existe entre los usuario";
  35. }else{
  36. $pw=$this->GeneraPass();
  37. $user['password']=md5($pw);
  38. $this->Modeluser->update($user,$dato->id);
  39. $this->email->from('info@programofacil.com');
  40. $this->email->to($dato->email);
  41. $this->email->subject('Recuperacion de Contraseña');
  42. $this->email->message("Su contraseña ha sido restablecido y se esta enviando su nueva contraseña la cual es: ".$pw);
  43. if($this->email->send()){
  44. $error['exito']=true;
  45. $error['alert']="Mensaje Enviado a su correo por favor revise su correo y estara su nueva contraseña";
  46. $error['url']=base_url()."olvideclave";
  47. $error['alertc']="alert alert-success alert-dismissible";
  48. }
  49. }
  50. }
  51. $error['errores']=$er;
  52. echo json_encode($error);
  53. }else{
  54. redirect(base_url(),'refresh');
  55. }
  56. }
  57. public function Index(){
  58. if($this->input->is_ajax_request()) {
  59. $this->Vista(array('vista' => 'Index','ajax'=>'ajax'));
  60. }else{
  61. $this->Vista(array('vista' => 'Index'));
  62. }
  63. }
  64. public function Login(){
  65. if($this->input->is_ajax_request()) {
  66. if(!empty($this->perfil)){
  67. $this->Vista(array('vista'=>'Index','ajax'=>'ajax'));
  68. }else{
  69. $this->Vista(array('vista'=>'Login','ajax'=>'ajax'));
  70. }
  71. }else{
  72. if(!empty($this->perfil)){
  73. redirect(base_url());
  74. }else{
  75. $this->Vista(array('vista'=>'Login'));
  76. }
  77. }
  78. }
  79. public function Objetivos(){
  80. if($this->input->is_ajax_request()){
  81. $this->Vista(array('vista'=>'Objetivos','ajax'=>'ajax'));
  82. }else{
  83. $this->Vista(array('vista'=>'Objetivos'));
  84. }
  85. }
  86. public function Organigrama(){
  87. if($this->input->is_ajax_request()) {
  88. $this->Vista(array('vista' => 'Organigrama','ajax'=>'ajax'));
  89. }else{
  90. $this->Vista(array('vista' => 'Organigrama'));
  91. }
  92. }
  93. function Recupera(){
  94. $this->form_validation->set_rules('email', 'Correo', 'trim|valid_email|min_length[15]|max_length[150]|required');
  95. $this->form_validation->set_message('required', 'El %s es requerido');
  96. $this->form_validation->set_message('max_length', 'El %s tiene mas caracteres de %s caracteres permitidos');
  97. $this->form_validation->set_message('min_length', 'El %s acepta como minimo %s caracteres');
  98. }
  99. public function Session(){
  100. if($this->input->is_ajax_request()){
  101. $this->Validar('');
  102. $er=['email'=>'','password'=>''];
  103. $error=['exito'=>false];
  104. if($this->form_validation->run() == FALSE){
  105. $er['email']=form_error('email');
  106. $er['password']=form_error('password');
  107. }else{
  108. if(empty($er['email']) && empty($er['password'])){
  109. $user=$this->Modeluser->get($this->input->post(null,true));
  110. if($user!=NULL){
  111. $user->type_id=$this->Modeltype->get(array('id'=>$user->type_id));
  112. $error['exito']=true;
  113. $data = array(
  114. 'is_logued_in' => TRUE,
  115. 'id' => $user->id,
  116. 'Perfil' => $user->type_id->name,
  117. 'Nombre' => $user->name,
  118. 'Apellidos' => $user->apellidos,
  119. 'Img' => $user->image_id
  120. );
  121. $this->session->set_userdata($data);
  122. $error['url']=base_url()."paneladmin";
  123. }else{
  124. $error['data']=$user;
  125. $error['general']="Verifique sus datos por favor";
  126. }
  127. }
  128. }
  129. $error['errores']=$er;
  130. echo json_encode($error);
  131. }
  132. }
  133. public function Salir(){
  134. if(!empty($this->session->userdata('Perfil'))){
  135. $this->session->sess_destroy();
  136. redirect(base_url());
  137. }else{
  138. redirect(base_url());
  139. }
  140. }
  141. public function Servicios(){
  142. if($this->input->is_ajax_request()){
  143. $this->Vista(array('vista' => 'Servicios','ajax'=>'ajax'));
  144. }else{
  145. $this->Vista(array('vista' => 'Servicios'));
  146. }
  147. }
  148. public function Vision(){
  149. if($this->input->is_ajax_request()) {
  150. $this->Vista(array('vista' => 'Vision','ajax'=>'ajax'));
  151. }else{
  152. $this->Vista(array('vista' => 'Vision'));
  153. }
  154. }
  155. private function Validar($dato=null){
  156. $this->form_validation->set_rules('password', 'password', 'trim|min_length[6]|max_length[15]|required');
  157. if(!empty($dato)){
  158. $this->form_validation->set_rules('email', 'Correo', 'trim|required|xss_clean|is_unique[users.email]|min_length[6]');
  159. $this->form_validation->set_rules('name', 'Nombre', 'trim|required|xss_clean|min_length[6]');
  160. $this->form_validation->set_rules('apellidos', 'Apellidos', 'trim|required|xss_clean|min_length[6]');
  161. $this->form_validation->set_rules('date', 'Fecha de Nacimiento', 'trim|required|xss_clean');
  162. $this->form_validation->set_message('is_unique', 'El %s ya esta en uso');
  163. }else{
  164. $this->form_validation->set_rules('email', 'Correo', 'trim|valid_email|min_length[15]|max_length[150]|required');
  165. }
  166. $this->form_validation->set_message('required', 'El %s es requerido');
  167. $this->form_validation->set_message('max_length', 'El %s tiene mas caracteres de %s caracteres permitidos');
  168. $this->form_validation->set_message('min_length', 'El %s acepta como minimo %s caracteres');
  169. }
  170. public function Vista($array){
  171. if(!empty($array['ajax'])){
  172. $this->load->view('Static/'.$array['vista'],$array);
  173. }else{
  174. $this->load->view('Layout/Header');
  175. $this->load->view('Static/'.$array['vista'],$array);
  176. $this->load->view('Layout/Footer');
  177. }
  178. }
  179. }