Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.55 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. class Action extends CI_Controller
  4. {
  5. protected $type;
  6. function index()
  7. {
  8. show_error("The action you have requested is not allowed.", 403, "An Error Was Encountered");
  9. }
  10. function register()
  11. {
  12. $this->type = "login";
  13. $this->load->helper("form");
  14. $this->load->library("form_validation");
  15. $this->form_validation->set_rules("username", "username", "trim|required|max_length[10]|min_length[1]");
  16. $this->form_validation->set_rules("password", "password", "trim|required|min_length[1]");
  17. $this->form_validation->set_rules("passver", "second password", "trim|required|min_length[1]|matches[password]");
  18. $this->form_validation->set_rules("email", "email", "trim|required|min_length[1]|valid_email");
  19. $this->form_validation->set_rules("phone", "phone", "trim|required|min_length[1]");
  20. $this->form_validation->set_rules("g-recaptcha-response", "captcha", "required");
  21. if($this->form_validation->run() == FALSE)
  22. {
  23. $this->load->library("pageloadpreset");
  24. $this->pageloadpreset->load("register", $this);
  25. }
  26. else
  27. {
  28. $this->form_validation->set_rules("g-recaptcha-response", "captcha", "callback_captcha_check");
  29. if($this->form_validation->run() == FALSE)
  30. {
  31. $this->load->library("pageloadpreset");
  32. $this->pageloadpreset->load("register", $this);
  33. }
  34. else
  35. {
  36. $this->form_validation->set_rules("phone", "phone", "callback_phone_check");
  37. if($this->form_validation->run() == FALSE)
  38. {
  39. $this->load->library("pageloadpreset");
  40. $this->pageloadpreset->load("register", $this);
  41. }
  42. else
  43. {
  44. //$this->form_validation->set_rules("password", "password", "callback_querydb");
  45. }
  46. }
  47. }
  48. }
  49. function login()
  50. {
  51. $this->type = "login";
  52. $this->load->helper("form");
  53. $this->load->library("form_validation");
  54. $this->form_validation->set_rules("username", "username", "trim|required|max_length[10]|min_length[1]");
  55. $this->form_validation->set_rules("password", "password", "trim|required|min_length[1]");
  56. if($this->form_validation->run() == FALSE)
  57. {
  58. $this->load->library("pageloadpreset");
  59. $this->pageloadpreset->load("login", $this);
  60. }
  61. else
  62. {
  63. $this->form_validation->set_rules("password", "password", "callback_querydb");
  64. if($this->form_validation->run() == FALSE)
  65. {
  66. $this->load->library("pageloadpreset");
  67. $this->pageloadpreset->load("login", $this);
  68. }
  69. else
  70. {
  71. echo "ok";
  72. }
  73. }
  74. }
  75. function querydb($parameter)
  76. {
  77. $this->load->model("dbsystem", "", TRUE);
  78. if($this->type == "login")
  79. {
  80. $username = $this->input->post("username");
  81. $password = $parameter;
  82. $loginResult = $this->dbsystem->login($username, $password);
  83. if($loginResult != "mse")
  84. {
  85. if($loginResult != "unf")
  86. {
  87. if($loginResult != "wp")
  88. {
  89. $sessionArray = array();
  90. foreach($loginResult as $row)
  91. {
  92. $sessionArray = array(
  93. "username" => $row->username
  94. );
  95. $this->session->set_userdata("logged_in", $sessionArray);
  96. }
  97. return TRUE;
  98. }
  99. else
  100. {
  101. $this->form_validation->set_message("querydb", "Invalid password");
  102. return FALSE;
  103. }
  104. }
  105. else
  106. {
  107. $this->form_validation->set_message("querydb", "This user was not found");
  108. return FALSE;
  109. }
  110. }
  111. else
  112. {
  113. show_error("A fatal error occured, the site admins have been notified. If this error persists, try again later.", 500, "Error");
  114. log_message("error", "Mysql connection error!");
  115. return FALSE;
  116. }
  117. }
  118. else if($this->type == "register")
  119. {
  120.  
  121. }
  122. }
  123. function captcha_check($captchaResponse)
  124. {
  125. $ip = $this->input->ip_address();
  126. $pkey = "6LeewiYTAAAAAA7MZt_Rn62qsIwRV3IjrtBpOUS3";
  127. $url = "https://www.google.com/recaptcha/api/siteverify?secret=".$pkey."&response=".$captchaResponse."&remoteip=".$ip."";
  128. $req = curl_init($url);
  129. curl_setopt($req, CURLOPT_RETURNTRANSFER, true);
  130. curl_setopt($req, CURLOPT_SSL_VERIFYPEER, false);
  131. if($res = curl_exec($req))
  132. {
  133. curl_close($req);
  134. $res = json_decode($res, true);
  135. if($res['success'] == true)
  136. {
  137. return TRUE;
  138. }
  139. else
  140. {
  141. $this->form_validation->set_message("captcha_check", "Invalid captcha");
  142. return FALSE;
  143. }
  144. }
  145. else
  146. {
  147. show_error("A fatal error occured, the site admins have been notified. If this error persists, try again later.", 500, "Error");
  148. log_message("error", "Curl error!");
  149. }
  150. }
  151. function phone_check($phone)
  152. {
  153. $access_key = "68b7972ae57423e8cfb197fd4dbf53d0";
  154. $url = "http://apilayer.net/api/validate?access_key=".$access_key."&number=".$phone."&country_code=&format=1";
  155. $req = curl_init($url);
  156. curl_setopt($req, CURLOPT_RETURNTRANSFER, true);
  157. if($res = curl_exec($req))
  158. {
  159. curl_close($req);
  160. $res = json_decode($res, true);
  161. if($res['success'] == "true")
  162. {
  163. return TRUE;
  164. }
  165. else
  166. {
  167. $this->form_validation->set_message("phone_check", "Invalid phone number");
  168. return FALSE;
  169. }
  170. }
  171. else
  172. {
  173. show_error("A fatal error occured, the site admins have been notified. If this error persists, try again later.", 500, "Error");
  174. log_message("error", "Curl error!");
  175. }
  176. }
  177. }
  178. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement