Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // RedBeanPHP connection file
- <?php
- require 'rb.php';
- R::setup( 'mysql:host=localhost;dbname=test',
- 'Artjom', 'pass' );
- // starting session
- session_start();
- ?>
- // ---------------------------------------- //
- // Signup
- <?php
- // RedBeanPHP connection
- require 'libs/db.php';
- $data = $_POST;
- if(isset($data['dosignup'])){
- $user = R::dispense('users');
- $user->email = $data['email'];
- $user->password = password_hash($data['password'], PASSWORD_DEFAULT);
- $user->name = $data['name'];
- $user->status = "Standard";
- $date = date('d.m.y', strtotime(' + 7 days'));
- $user->expire = $date;
- }
- // checking for pass input
- if($data['password'] != $data['password2']){
- echo "<h3>Passwords doesnt atch.</h3>";
- echo "<button> <a href='https://urwebsite.com/logreg'>Try again</a></button>";
- }
- else
- {
- // checking for email in DB
- if(R::count('users', "email = ?", array($data['email'])) >0 ){
- echo "<h3>email already exist.</h3>";
- echo "<button> <a href='https://urwebsite.com/logreg'>Try again</a></button>";
- }
- // saving user
- R::store($user);
- ?>
- // ----------------------------------------- //
- //LOGIN
- <?php
- // connect to RedBeanPHP
- require 'libs/db.php';
- $data = $_POST;
- // login process
- if(isset($data['login'])){
- $user = R::findOne('users', 'email = ?', array($data['email']));
- echo gettype($date1);
- // status change if found in db
- if( $user ){
- $date1 = date('d.m.Y');
- $date2 = $user['expire'];
- if(strtotime($date1) >= strtotime($date2)){
- $user->status = 'unsub';
- R::store($user);
- }
- // password check if email found
- if(password_verify($data['password'], $user->password)){
- $_SESSION['logged_user'] = $user;
- }
- else{
- echo "<h3>password is incorrect</h3>";
- echo "<br><button> <a href='https://urwebsite.com/logreg'>try again</a></button>";
- }
- }
- // if mail not exist - output
- else{
- echo "<h3>email not found</h3>";
- echo "<br><button> <a href='https://urwebsite.com/logreg'>try again</a></button>";
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement