mostly filebased Content Presentation System
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

user.php 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace Controller;
  3. class User {
  4. private $db;
  5. function __construct() {
  6. // $this->db = new \DB\SQL('sqlite:data/login.sqlite');
  7. // $this->db->exec("CREATE TABLE IF NOT EXISTS users
  8. // (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  9. // email varchar(128) NULL DEFAULT 'anonymous',
  10. // password varchar(128) NULL,
  11. // balance REAL
  12. // )"
  13. // );
  14. $this->db = new \DB\Jig('data/');
  15. }
  16. function login() {
  17. $f3 = \Base::instance();
  18. $audit = \Audit::instance();
  19. $username = $f3->get('GET.uname');
  20. $password = $f3->get('GET.psw');
  21. $mapper = new \DB\Jig\Mapper($this->db, 'users');
  22. $auth = new \Auth(
  23. $mapper,
  24. array('id' => 'email', 'pw' => 'password')
  25. );
  26. if ( $auth->login($username,$password) ) {
  27. $mapper->load(array("@email = ?", $username));
  28. new \Session();
  29. $f3->mset(array(
  30. 'SESSION.login.email' => $mapper->email,
  31. 'SESSION.login.balance' => 100
  32. ));
  33. $f3->reroute('/dashboard');
  34. } else {
  35. echo "no success";
  36. }
  37. $f3->set('template', "login.htm");
  38. }
  39. function register() {
  40. $f3 = \Base::instance();
  41. $audit = \Audit::instance();
  42. //var_dump($f3->get("GET"));
  43. if ( $f3->get('GET.psw') == $f3->get('GET.psw-repeat')) {
  44. $password = $f3->get('GET.psw');
  45. }
  46. $email = $f3->get('GET.email');
  47. if ( $password && $email) {
  48. $mapper = new \DB\Jig\Mapper($this->db, 'users');
  49. $mapper->email = $email;
  50. $mapper->password = $password;
  51. $mapper->save();
  52. $f3->reroute('/login');
  53. }
  54. $f3->set('template', "register.htm");
  55. }
  56. }