1<?php
2
3 /* Template Name: login-new */
4 do_action('user_redirect_if_logged_in');
5
6 // get_header();
7 $login = home_url()."/login-new/";
8 $dashboard = home_url()."/dashboard/";
9
10 if(isset($_REQUEST['signin'])){
11 $email = $_POST['email'];
12 $password = $_POST['password'];
13 $creds = array();
14 $creds['user_login'] = $_POST['email'];
15 $creds['user_password'] = $_POST['password'];
16 $creds['remember'] = false;
17 $user = wp_signon( $creds, false );
18 //if ( is_wp_error($user) )
19 //{
20 // header("location:$login");
21 //}
22 //else
23 //{
24 // header("location:$dashboard");
25 //}
26
27 $user = wp_signon( $creds);
28
29 if(isset($user->errors)){
30 // if(is_wp_error($user)) {
31 echo $user->get_error_message();
32 die;
33 }else{ //successfully logged in
34 session_start(); //check for wp_session storage
35 $_SESSION["new_dashboard"] = '1'; //if you want to redirect user to a new page or set any conditions on login
36
37 if ($user->is_admin == '1') {
38 $dashboard = home_url()."/?page=old-dashboard";
39 } else {
40 $dashboard = home_url()."/?page=new-dashboard";
41 }
42
43 //set cookie for remember me //save user login details as cookie if remember me is set, so that if user logs out next time and comes to this log in page, username & password auto fills by checking
44 $user_login_details = $email.'_pass_'.$password;
45 if(!empty($_POST["remember"])) {
46 setcookie ("user_login_details",$user_login_details,time()+ (10 * 365 * 24 * 60 * 60)); //set cookie time as per you need
47 } else { //remove login details from cookie
48 if(isset($_COOKIE["user_login_details"])) {
49 setcookie ("user_login_details","");
50 }
51 }
52 wp_redirect($dashboard);
53 exit;
54 }
55 }
56
57 if(isset($_COOKIE["user_login_details"])) {
58 $login_details = $_COOKIE["user_login_details"];
59 $login_details = explode('_pass_', $login_details);
60 $email_set = $login_details[0];
61 $pass_set = $login_details[1];
62 }
63
64 ?>
65
66<!DOCTYPE html>
67<html lang="en">
68
69<head>
70<?php
71 global $wpdb;
72 $db_name = $wpdb->dbname;
73?>
74
75 <title>Sign In</title>
76
77</head>
78
79<title>New Login</title>
80
81<div class="container-fluid">
82 <div class="row">
83 <div class="col-md-4 card-body">
84
85 <div class="card">
86 <div class="card-body">
87
88 <h3 class="h3">Login</h3>
89
90 <form method="POST" action="">
91 <div class="form-group">
92 <label>Email address</label>
93 <div class="input-group">
94 <input id="email" type="email" class="form-control" name="email" value="<?php if(isset($email_set)){ echo $email_set; } ?>" required />
95 </div>
96 </div>
97 <div class="form-group">
98
99 <label class="form-control-label">Password</label>
100
101 <a href="<?php echo site_url(); ?>/password-reset/" class="small text-muted text-underline--dashed border-primary">Lost password?</a>
102
103 <div class="input-group input-group-merge">
104
105 <input id="password" type="password" value="<?php if(isset($pass_set)){ echo $pass_set; } ?>" class="form-control" name="password" required />
106
107 <a href="#/" onClick="show_pass()" class="primary_color">
108 <i class="fas fa-eye"></i>
109 </a>
110 </div>
111
112 <input type="checkbox" name="remember" class="custom-control-input" id="remember" >
113 <label class="custom-control-label" for="remember">Remember Me</label>
114
115 <button type="submit" id="signin" name="signin">
116
117 </button>
118
119 </div>
120 </form>
121
122 </div>
123 </div>
124 </div>
125 </div>
126</div>
127<script>
128function show_pass() {
129 var x = document.getElementById("password");
130 if (x.type === "password") {
131 x.type = "text";
132 } else {
133 x.type = "password";
134 }
135}
136</script>
137
138<?php get_footer();?>
139
1<?php
2
3function auto_login( $user ) {
4 $username = $user;
5 // log in automatically
6 if ( !is_user_logged_in() ) {
7 $user = get_userdatabylogin( $username );
8 $user_id = $user->ID;
9 wp_set_current_user( $user_id, $user_login );
10 wp_set_auth_cookie( $user_id );
11 do_action( 'wp_login', $user_login );
12 }
13}
14?>
15