Guest User

Untitled

a guest
Feb 10th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.61 KB | None | 0 0
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class Main extends CI_Controller {
  4.  
  5. public $status;
  6. public $roles;
  7.  
  8. function __construct(){
  9. parent::__construct();
  10. $this->load->model('User_model', 'user_model', TRUE);
  11. $this->load->library('form_validation');
  12. $this->form_validation->set_error_delimiters('<div class="error">', '</div>');
  13. $this->status = $this->config->item('status');
  14. $this->roles = $this->config->item('roles');
  15. }
  16.  
  17.  
  18. public function register()
  19. {
  20.  
  21. $this->form_validation->set_rules('firstname', 'First Name', 'required');
  22. $this->form_validation->set_rules('lastname', 'Last Name', 'required');
  23. $this->form_validation->set_rules('email', 'Email', 'required|valid_email');
  24.  
  25. if ($this->form_validation->run() == FALSE) {
  26. $this->load->view('bootstrap/header');
  27. $this->load->view('register');
  28. $this->load->view('bootstrap/footer');
  29. }else{
  30. if($this->user_model->isDuplicate($this->input->post('email'))){
  31. $this->session->set_flashdata('flash_message', 'User email already exists');
  32. redirect(site_url().'main/login');
  33. }else{
  34.  
  35. $clean = $this->security->xss_clean($this->input->post(NULL, TRUE));
  36. $id = $this->user_model->insertUser($clean);
  37. $token = $this->user_model->insertToken($id);
  38.  
  39. $qstring = base64_encode($token);
  40. $url = site_url() . 'main/complete/token/' . $qstring;
  41. $link = '<a href="' . $url . '">' . $url . '</a>';
  42.  
  43. $message = '';
  44. $message .= '<strong>You have signed up with our website</strong><br>';
  45. $message .= '<strong>Please click:</strong> ' . $link;
  46. echo $message; //send this in email
  47. exit;
  48.  
  49.  
  50. };
  51. }
  52. }
  53. };
  54.  
  55. <?php
  56. class User_model extends CI_Model {
  57. public $status;
  58. public $roles;
  59.  
  60. function __construct(){
  61. // Call the Model constructor
  62. parent::__construct();
  63. $this->status = $this->config->item('status');
  64. $this->roles = $this->config->item('roles');
  65. }
  66.  
  67. public function insertUser($d)
  68. {
  69. $string = array(
  70. 'first_name'=>$d['firstname'],
  71. 'last_name'=>$d['lastname'],
  72. 'email'=>$d['email'],
  73. 'role'=>$this->roles[0],
  74. 'status'=>$this->status[0]
  75. );
  76. $q = $this->db->insert_string('users',$string);
  77. $this->db->query($q);
  78. return $this->db->insert_id();
  79. }
  80.  
  81. public function isDuplicate($email)
  82. {
  83. $this->db->get_where('users', array('email' => $email), 1);
  84. return $this->db->affected_rows() > 0 ? TRUE : FALSE;
  85. }
  86.  
  87. public function insertToken($user_id)
  88. {
  89. $token = substr(sha1(rand()), 0, 30);
  90. $date = date('Y-m-d');
  91.  
  92. $string = array(
  93. 'token'=> $token,
  94. 'user_id'=>$user_id,
  95. 'created'=>$date
  96. );
  97. $query = $this->db->insert_string('tokens',$string);
  98. $this->db->query($query);
  99. return $token;
  100.  
  101. }
  102. }
  103. ?>
  104.  
  105. <div class="col-lg-4 col-lg-offset-4">
  106. <h2>Hello There</h2>
  107. <h5>Please enter the required information below.</h5>
  108. <?php
  109. $fattr = array('class' => 'form-signin');
  110. echo form_open('/main/register', $fattr); ?>
  111. <div class="form-group">
  112. <?php echo form_input(array('name'=>'firstname', 'id'=> 'firstname', 'placeholder'=>'First Name', 'class'=>'form-control', 'value' => set_value('firstname'))); ?>
  113. <?php echo form_error('firstname');?>
  114. </div>
  115. <div class="form-group">
  116. <?php echo form_input(array('name'=>'lastname', 'id'=> 'lastname', 'placeholder'=>'Last Name', 'class'=>'form-control', 'value'=> set_value('lastname'))); ?>
  117. <?php echo form_error('lastname');?>
  118. </div>
  119. <div class="form-group">
  120. <?php echo form_input(array('name'=>'email', 'id'=> 'email', 'placeholder'=>'Email', 'class'=>'form-control', 'value'=> set_value('email'))); ?>
  121. <?php echo form_error('email');?>
  122. </div>
  123. <?php echo form_submit(array('value'=>'Sign up', 'class'=>'btn btn-lg btn-primary btn-block')); ?>
  124. <?php echo form_close(); ?>
  125. </div>
  126.  
  127. <?php
  128.  
  129. defined('BASEPATH') OR exit('No direct script access allowed');
  130.  
  131. $config['roles'] = array('subscriber', 'admin');
  132. $config['status'] = array('pending', 'approved');
  133. /*
  134. |--------------------------------------------------------------------------
  135. | Base Site URL
  136. |--------------------------------------------------------------------------
  137. |
  138. | URL to your CodeIgniter root. Typically this will be your base URL,
  139. | WITH a trailing slash:
  140. |
  141. | http://example.com/
  142. |
  143. | WARNING: You MUST set this value!
  144. |
  145. | If it is not set, then CodeIgniter will try guess the protocol and path
  146. | your installation, but due to security concerns the hostname will be set
  147. | to $_SERVER['SERVER_ADDR'] if available, or localhost otherwise.
  148. | The auto-detection mechanism exists only for convenience during
  149. | development and MUST NOT be used in production!
  150. |
  151. | If you need to allow multiple domains, remember that this file is still
  152. | a PHP script and you can easily do that on your own.
  153. |
  154. */
  155.  
  156. $config['base_url'] = 'http://subdomain.example.com/';
  157. /*
  158. |--------------------------------------------------------------------------
  159. | Index File
  160. |--------------------------------------------------------------------------
  161. |
  162. | Typically this will be your index.php file, unless you've renamed it to
  163. | something else. If you are using mod_rewrite to remove the page set this
  164. | variable so that it is blank.
  165. |
  166. */
  167.  
  168. $config['index_page'] = '';
  169.  
  170. /*
  171. |--------------------------------------------------------------------------
  172. | URI PROTOCOL
  173. |--------------------------------------------------------------------------
  174. |
  175. | This item determines which server global should be used to retrieve the
  176. | URI string. The default setting of 'REQUEST_URI' works for most servers.
  177. | If your links do not seem to work, try one of the other delicious flavors:
  178. |
  179. | 'REQUEST_URI' Uses $_SERVER['REQUEST_URI']
  180. | 'QUERY_STRING' Uses $_SERVER['QUERY_STRING']
  181. | 'PATH_INFO' Uses $_SERVER['PATH_INFO']
  182. |
  183. | WARNING: If you set this to 'PATH_INFO', URIs will always be URL-decoded!
  184. */
  185.  
  186. $config['uri_protocol'] = 'REQUEST_URI';
  187.  
  188. /*
  189. |--------------------------------------------------------------------------
  190. | URL suffix
  191. |--------------------------------------------------------------------------
  192. |
  193. | This option allows you to add a suffix to all URLs generated by CodeIgniter.
  194. | For more information please see the user guide:
  195. |
  196. | https://codeigniter.com/user_guide/general/urls.html
  197. */
  198.  
  199. $config['url_suffix'] = '';
  200.  
  201. /*
  202. |--------------------------------------------------------------------------
  203. | Default Language
  204. |--------------------------------------------------------------------------
  205. |
  206. | This determines which set of language files should be used. Make sure
  207. | there is an available translation if you intend to use something other
  208. | than english.
  209. |
  210. */
  211.  
  212. $config['language'] = 'english';
  213.  
  214. /*
  215. |--------------------------------------------------------------------------
  216. | Default Character Set
  217. |--------------------------------------------------------------------------
  218. |
  219. | This determines which character set is used by default in various methods
  220. | that require a character set to be provided.
  221. |
  222. | See http://php.net/htmlspecialchars for a list of supported charsets.
  223. |
  224. */
  225.  
  226. $config['charset'] = 'UTF-8';
  227.  
  228. /*
  229. |--------------------------------------------------------------------------
  230. | Enable/Disable System Hooks
  231. |--------------------------------------------------------------------------
  232. |
  233. | If you would like to use the 'hooks' feature you must enable it by
  234. | setting this variable to TRUE (boolean). See the user guide for details.
  235. |
  236. */
  237.  
  238. $config['enable_hooks'] = FALSE;
  239.  
  240. /*
  241. |--------------------------------------------------------------------------
  242. | Class Extension Prefix
  243. |--------------------------------------------------------------------------
  244. |
  245. | This item allows you to set the filename/classname prefix when extending
  246. | native libraries. For more information please see the user guide:
  247. |
  248. | https://codeigniter.com/user_guide/general/core_classes.html
  249. | https://codeigniter.com/user_guide/general/creating_libraries.html
  250. |
  251. */
  252.  
  253. $config['subclass_prefix'] = 'MY_';
  254.  
  255. /*
  256. |--------------------------------------------------------------------------
  257. | Composer auto-loading
  258. |--------------------------------------------------------------------------
  259. |
  260. | Enabling this setting will tell CodeIgniter to look for a Composer
  261. | package auto-loader script in application/vendor/autoload.php.
  262. |
  263. | $config['composer_autoload'] = TRUE;
  264. |
  265. | Or if you have your vendor/ directory located somewhere else, you
  266. | can opt to set a specific path as well:
  267. |
  268. | $config['composer_autoload'] = '/path/to/vendor/autoload.php';
  269. |
  270. | For more information about Composer, please visit http://getcomposer.org/
  271. |
  272. | Note: This will NOT disable or override the CodeIgniter-specific
  273. | autoloading (application/config/autoload.php)
  274. */
  275.  
  276. $config['composer_autoload'] = '/vendor/autoload.php';
  277.  
  278. /*
  279. |--------------------------------------------------------------------------
  280. | Allowed URL Characters
  281. |--------------------------------------------------------------------------
  282. |
  283. | This lets you specify which characters are permitted within your URLs.
  284. | When someone tries to submit a URL with disallowed characters they will
  285. | get a warning message.
  286. |
  287. | As a security measure you are STRONGLY encouraged to restrict URLs to
  288. | as few characters as possible. By default only these are allowed: a-z 0-9~%.:_-
  289. |
  290. | Leave blank to allow all characters -- but only if you are insane.
  291. |
  292. | The configured value is actually a regular expression character group
  293. | and it will be executed as: ! preg_match('/^[<permitted_uri_chars>]+$/i
  294. |
  295. | DO NOT CHANGE THIS UNLESS YOU FULLY UNDERSTAND THE REPERCUSSIONS!!
  296. |
  297. */
  298. $config['permitted_uri_chars'] = 'a-z 0-9~%.:_-';
  299.  
  300. /*
  301. |--------------------------------------------------------------------------
  302. | Enable Query Strings
  303. |--------------------------------------------------------------------------
  304. |
  305. | By default CodeIgniter uses search-engine friendly segment based URLs:
  306. | example.com/who/what/where/
  307. |
  308. | By default CodeIgniter enables access to the $_GET array. If for some
  309. | reason you would like to disable it, set 'allow_get_array' to FALSE.
  310. |
  311. | You can optionally enable standard query string based URLs:
  312. | example.com?who=me&what=something&where=here
  313. |
  314. | Options are: TRUE or FALSE (boolean)
  315. |
  316. | The other items let you set the query string 'words' that will
  317. | invoke your controllers and its functions:
  318. | example.com/index.php?c=controller&m=function
  319. |
  320. | Please note that some of the helpers won't work as expected when
  321. | this feature is enabled, since CodeIgniter is designed primarily to
  322. | use segment based URLs.
  323. |
  324. */
  325. $config['allow_get_array'] = TRUE;
  326. $config['enable_query_strings'] = FALSE;
  327. $config['controller_trigger'] = 'c';
  328. $config['function_trigger'] = 'm';
  329. $config['directory_trigger'] = 'd';
  330.  
  331. /*
  332. |--------------------------------------------------------------------------
  333. | Error Logging Threshold
  334. |--------------------------------------------------------------------------
  335. |
  336. | You can enable error logging by setting a threshold over zero. The
  337. | threshold determines what gets logged. Threshold options are:
  338. |
  339. | 0 = Disables logging, Error logging TURNED OFF
  340. | 1 = Error Messages (including PHP errors)
  341. | 2 = Debug Messages
  342. | 3 = Informational Messages
  343. | 4 = All Messages
  344. |
  345. | You can also pass an array with threshold levels to show individual error types
  346. |
  347. | array(2) = Debug Messages, without Error Messages
  348. |
  349. | For a live site you'll usually only enable Errors (1) to be logged otherwise
  350. | your log files will fill up very fast.
  351. |
  352. */
  353.  
  354. $config['log_threshold'] = 0;
  355.  
  356. /*
  357. |--------------------------------------------------------------------------
  358. | Error Logging Directory Path
  359. |--------------------------------------------------------------------------
  360. |
  361. | Leave this BLANK unless you would like to set something other than the default
  362. | application/logs/ directory. Use a full server path with trailing slash.
  363. |
  364. */
  365.  
  366. $config['log_path'] = '';
  367.  
  368. /*
  369. |--------------------------------------------------------------------------
  370. | Log File Extension
  371. |--------------------------------------------------------------------------
  372. |
  373. | The default filename extension for log files. The default 'php' allows for
  374. | protecting the log files via basic scripting, when they are to be stored
  375. | under a publicly accessible directory.
  376. |
  377. | Note: Leaving it blank will default to 'php'.
  378. |
  379. */
  380.  
  381. $config['log_file_extension'] = '';
  382.  
  383. /*
  384. |--------------------------------------------------------------------------
  385. | Log File Permissions
  386. |--------------------------------------------------------------------------
  387. |
  388. | The file system permissions to be applied on newly created log files.
  389. |
  390. | IMPORTANT: This MUST be an integer (no quotes) and you MUST use octal
  391. | integer notation (i.e. 0700, 0644, etc.)
  392. */
  393.  
  394. $config['log_file_permissions'] = 0644;
  395.  
  396. /*
  397. |--------------------------------------------------------------------------
  398. | Date Format for Logs
  399. |--------------------------------------------------------------------------
  400. |
  401. | Each item that is logged has an associated date. You can use PHP date
  402. | codes to set your own date formatting
  403. |
  404. */
  405.  
  406. $config['log_date_format'] = 'Y-m-d H:i:s';
  407.  
  408. /*
  409. |--------------------------------------------------------------------------
  410. | Error Views Directory Path
  411. |--------------------------------------------------------------------------
  412. |
  413. | Leave this BLANK unless you would like to set something other than the default
  414. | application/views/errors/ directory. Use a full server path with trailing slash.
  415. |
  416.  
  417. */
  418.  
  419. $config['error_views_path'] = '';
  420.  
  421. /*
  422. |--------------------------------------------------------------------------
  423. | Cache Directory Path
  424. |--------------------------------------------------------------------------
  425. |
  426. | Leave this BLANK unless you would like to set something other than the default
  427. | application/cache/ directory. Use a full server path with trailing slash.
  428. |
  429.  
  430. */
  431.  
  432. $config['cache_path'] = '';
  433.  
  434. /*
  435. |--------------------------------------------------------------------------
  436. | Cache Include Query String
  437. |--------------------------------------------------------------------------
  438. |
  439. | Whether to take the URL query string into consideration when generating
  440. | output cache files. Valid options are:
  441. |
  442. | FALSE = Disabled
  443. | TRUE = Enabled, take all query parameters into account.
  444. | Please be aware that this may result in numerous cache
  445. | files generated for the same page over and over again.
  446. | array('q') = Enabled, but only take into account the specified list
  447. | of query parameters.
  448. |
  449.  
  450. */
  451.  
  452. $config['cache_query_string'] = FALSE;
  453.  
  454. /*
  455. |--------------------------------------------------------------------------
  456. | Encryption Key
  457. |--------------------------------------------------------------------------
  458. |
  459. | If you use the Encryption class, you must set an encryption key.
  460. | See the user guide for more info.
  461. |
  462. | https://codeigniter.com/user_guide/libraries/encryption.html
  463. |
  464.  
  465. */
  466.  
  467. $config['encryption_key'] = '';
  468.  
  469. /*
  470. |--------------------------------------------------------------------------
  471. | Session Variables
  472. |--------------------------------------------------------------------------
  473. |
  474. | 'sess_driver'
  475. |
  476. | The storage driver to use: files, database, redis, memcached
  477. |
  478. | 'sess_cookie_name'
  479. |
  480. | The session cookie name, must contain only [0-9a-z_-] characters
  481. |
  482. | 'sess_expiration'
  483. |
  484. | The number of SECONDS you want the session to last.
  485. | Setting to 0 (zero) means expire when the browser is closed.
  486. |
  487. | 'sess_save_path'
  488. |
  489. | The location to save sessions to, driver dependent.
  490. |
  491. | For the 'files' driver, it's a path to a writable directory.
  492. | WARNING: Only absolute paths are supported!
  493. |
  494. | For the 'database' driver, it's a table name.
  495. | Please read up the manual for the format with other session drivers.
  496. |
  497. | IMPORTANT: You are REQUIRED to set a valid save path!
  498. |
  499. | 'sess_match_ip'
  500. |
  501. | Whether to match the user's IP address when reading the session data.
  502. |
  503. | WARNING: If you're using the database driver, don't forget to update
  504. | your session table's PRIMARY KEY when changing this setting.
  505. |
  506. | 'sess_time_to_update'
  507. |
  508. | How many seconds between CI regenerating the session ID.
  509. |
  510. | 'sess_regenerate_destroy'
  511. |
  512. | Whether to destroy session data associated with the old session ID
  513. | when auto-regenerating the session ID. When set to FALSE, the data
  514. | will be later deleted by the garbage collector.
  515. |
  516. | Other session cookie settings are shared with the rest of the application,
  517. | except for 'cookie_prefix' and 'cookie_httponly', which are ignored here.
  518. |
  519.  
  520. */
  521.  
  522. $config['sess_driver'] = 'files';
  523.  
  524. $config['sess_cookie_name'] = 'ci_session';
  525.  
  526. $config['sess_expiration'] = 7200;
  527.  
  528. $config['sess_save_path'] = NULL;
  529.  
  530. $config['sess_match_ip'] = FALSE;
  531.  
  532. $config['sess_time_to_update'] = 300;
  533.  
  534. $config['sess_regenerate_destroy'] = FALSE;
  535.  
  536. /*
  537. |--------------------------------------------------------------------------
  538. | Cookie Related Variables
  539. |--------------------------------------------------------------------------
  540. |
  541. | 'cookie_prefix' = Set a cookie name prefix if you need to avoid collisions
  542. | 'cookie_domain' = Set to .your-domain.com for site-wide cookies
  543. | 'cookie_path' = Typically will be a forward slash
  544. | 'cookie_secure' = Cookie will only be set if a secure HTTPS connection exists.
  545. | 'cookie_httponly' = Cookie will only be accessible via HTTP(S) (no javascript)
  546. |
  547. | Note: These settings (with the exception of 'cookie_prefix' and
  548. | 'cookie_httponly') will also affect sessions.
  549. |
  550.  
  551. */
  552.  
  553. $config['cookie_prefix'] = '';
  554.  
  555. $config['cookie_domain'] = '';
  556.  
  557. $config['cookie_path'] = '/';
  558.  
  559. $config['cookie_secure'] = FALSE;
  560.  
  561. $config['cookie_httponly'] = FALSE;
  562.  
  563. /*
  564. |--------------------------------------------------------------------------
  565. | Standardize newlines
  566. |--------------------------------------------------------------------------
  567. |
  568. | Determines whether to standardize newline characters in input data,
  569. | meaning to replace rn, r, n occurrences with the PHP_EOL value.
  570. |
  571. | This is particularly useful for portability between UNIX-based OSes,
  572. | (usually n) and Windows (rn).
  573. |
  574.  
  575. */
  576.  
  577. $config['standardize_newlines'] = FALSE;
  578.  
  579. /*
  580. |--------------------------------------------------------------------------
  581. | Global XSS Filtering
  582. |--------------------------------------------------------------------------
  583. |
  584. | Determines whether the XSS filter is always active when GET, POST or
  585. | COOKIE data is encountered
  586. |
  587. | WARNING: This feature is DEPRECATED and currently available only
  588. | for backwards compatibility purposes!
  589. |
  590.  
  591. */
  592.  
  593. $config['global_xss_filtering'] = FALSE;
  594.  
  595. /*
  596. |--------------------------------------------------------------------------
  597. | Cross Site Request Forgery
  598. |--------------------------------------------------------------------------
  599. | Enables a CSRF cookie token to be set. When set to TRUE, token will be
  600. | checked on a submitted form. If you are accepting user data, it is strongly
  601. | recommended CSRF protection be enabled.
  602. |
  603. | 'csrf_token_name' = The token name
  604. | 'csrf_cookie_name' = The cookie name
  605. | 'csrf_expire' = The number in seconds the token should expire.
  606. | 'csrf_regenerate' = Regenerate token on every submission
  607. | 'csrf_exclude_uris' = Array of URIs which ignore CSRF checks
  608.  
  609. */
  610.  
  611. $config['csrf_protection'] = FALSE;
  612.  
  613. $config['csrf_token_name'] = 'csrf_test_name';
  614.  
  615. $config['csrf_cookie_name'] = 'csrf_cookie_name';
  616.  
  617. $config['csrf_expire'] = 7200;
  618.  
  619. $config['csrf_regenerate'] = TRUE;
  620.  
  621. $config['csrf_exclude_uris'] = array();
  622.  
  623. /*
  624. |--------------------------------------------------------------------------
  625. | Output Compression
  626. |--------------------------------------------------------------------------
  627. |
  628. | Enables Gzip output compression for faster page loads. When enabled,
  629. | the output class will test whether your server supports Gzip.
  630. | Even if it does, however, not all browsers support compression
  631. | so enable only if you are reasonably sure your visitors can handle it.
  632. |
  633. | Only used if zlib.output_compression is turned off in your php.ini.
  634. | Please do not use it together with httpd-level output compression.
  635. |
  636. | VERY IMPORTANT: If you are getting a blank page when compression is enabled it
  637. | means you are prematurely outputting something to your browser. It could
  638. | even be a line of whitespace at the end of one of your scripts. For
  639. | compression to work, nothing can be sent before the output buffer is called
  640. | by the output class. Do not 'echo' any values with compression enabled.
  641. |
  642.  
  643. */
  644.  
  645. $config['compress_output'] = FALSE;
  646.  
  647. /*
  648. |--------------------------------------------------------------------------
  649. | Master Time Reference
  650. |--------------------------------------------------------------------------
  651. |
  652. | Options are 'local' or any PHP supported timezone. This preference tells
  653. | the system whether to use your server's local time as the master 'now'
  654. | reference, or convert it to the configured one timezone. See the 'date
  655. | helper' page of the user guide for information regarding date handling.
  656. |
  657.  
  658. */
  659.  
  660. $config['time_reference'] = 'local';
  661.  
  662. /*
  663. |--------------------------------------------------------------------------
  664. | Rewrite PHP Short Tags
  665. |--------------------------------------------------------------------------
  666. |
  667. | If your PHP installation does not have short tag support enabled CI
  668. | can rewrite the tags on-the-fly, enabling you to utilize that syntax
  669. | in your view files. Options are TRUE or FALSE (boolean)
  670. |
  671. | Note: You need to have eval() enabled for this to work.
  672. |
  673.  
  674. */
  675.  
  676. $config['rewrite_short_tags'] = FALSE;
  677.  
  678. /*
  679. |--------------------------------------------------------------------------
  680. | Reverse Proxy IPs
  681. |--------------------------------------------------------------------------
  682. |
  683. | If your server is behind a reverse proxy, you must whitelist the proxy
  684. | IP addresses from which CodeIgniter should trust headers such as
  685. | HTTP_X_FORWARDED_FOR and HTTP_CLIENT_IP in order to properly identify
  686. | the visitor's IP address.
  687. |
  688. | You can use both an array or a comma-separated list of proxy addresses,
  689. | as well as specifying whole subnets. Here are a few examples:
  690. |
  691. | Comma-separated: '10.0.1.200,192.168.5.0/24'
  692. | Array: array('10.0.1.200', '192.168.5.0/24')
  693.  
  694. */
  695.  
  696. $config['proxy_ips'] = '';
Add Comment
Please, Sign In to add comment