Advertisement
Guest User

Some signup/in script

a guest
Oct 2nd, 2018
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.13 KB | None | 0 0
  1. // RedBeanPHP connection file
  2.  
  3. <?php
  4. require 'rb.php';
  5. R::setup( 'mysql:host=localhost;dbname=test',
  6.         'Artjom', 'pass' );
  7.  
  8. // starting session
  9. session_start();
  10.  
  11. ?>
  12. // ---------------------------------------- //
  13. // Signup
  14.  
  15. <?php
  16.  
  17. // RedBeanPHP connection
  18. require 'libs/db.php';
  19.  
  20. $data = $_POST;
  21.  
  22. if(isset($data['dosignup'])){
  23.     $user = R::dispense('users');
  24.     $user->email = $data['email'];
  25.     $user->password = password_hash($data['password'], PASSWORD_DEFAULT);
  26.     $user->name = $data['name'];
  27.     $user->status = "Standard";
  28.     $date = date('d.m.y', strtotime(' + 7 days'));
  29.     $user->expire = $date;
  30. }
  31.  
  32. // checking for pass input
  33. if($data['password'] != $data['password2']){
  34.     echo "<h3>Passwords doesnt atch.</h3>";
  35.     echo "<button> <a href='https://urwebsite.com/logreg'>Try again</a></button>";
  36. }
  37. else
  38. {
  39.  
  40. // checking for email in DB
  41. if(R::count('users', "email = ?", array($data['email'])) >0 ){
  42.     echo "<h3>email already exist.</h3>";
  43.     echo "<button> <a href='https://urwebsite.com/logreg'>Try again</a></button>";
  44. }
  45.  
  46.  
  47. // saving user
  48.     R::store($user);
  49. ?>
  50.  
  51.  
  52. // ----------------------------------------- //
  53.  
  54. //LOGIN
  55.  
  56. <?php
  57.  
  58. // connect to RedBeanPHP
  59. require 'libs/db.php';
  60.  
  61. $data = $_POST;
  62.  
  63. // login process
  64.  
  65. if(isset($data['login'])){
  66.     $user = R::findOne('users', 'email = ?', array($data['email']));
  67.      echo gettype($date1);
  68.     // status change if found in db
  69.     if( $user ){
  70.     $date1 = date('d.m.Y');
  71.     $date2 = $user['expire'];
  72.     if(strtotime($date1) >= strtotime($date2)){
  73.        $user->status = 'unsub';
  74.        R::store($user);
  75.     }
  76.     // password check if email found
  77.     if(password_verify($data['password'], $user->password)){
  78.         $_SESSION['logged_user'] = $user;
  79.     }
  80.     else{
  81.         echo "<h3>password is incorrect</h3>";
  82.         echo "<br><button> <a href='https://urwebsite.com/logreg'>try again</a></button>";
  83.     }
  84.    
  85.     }
  86.     // if mail not exist - output
  87.     else{
  88.         echo "<h3>email not found</h3>";
  89.         echo "<br><button> <a href='https://urwebsite.com/logreg'>try again</a></button>";
  90.     }
  91. }
  92. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement