-
Notifications
You must be signed in to change notification settings - Fork 8
/
register.php
235 lines (213 loc) · 9.8 KB
/
register.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<?php
require 'settings/tracy-2.6.2/src/tracy.php';
use Tracy\Debugger;
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
if( isset($_SESSION['user_id']) ){
if($_SESSION['rederect_url'] == "main_page"){
header("Location: index.php");
}else if($_SESSION['rederect_url'] == "form_admin"){
header("Location: formadmin.php");
}else{
header("Location: /");
}
}
require 'settings/database.login.php';
$message = '';
////////get settings ///////
if(!isset($isGetSetting)){
require 'get_setting_data.php';
}
$isRegistrationEnabled = getSetting("", "enableUserRegistration");
if($isRegistrationEnabled == "0"){
die("Registration not allowed!");
}
$emailSetting = getSetting("email", "");
if(empty($emailSetting)){
die("Error getting email server setting!");
}
$appMode = getSetting("", "appMode");
if($appMode == "0"){
//Debug mode
Debugger::enable();
}
if(!empty($_POST['username']) && !empty($_POST['email']) && !empty($_POST['password'])){
$query_users = "SELECT * FROM users WHERE username=:user_Name OR email=:user_Email";
$statement_users = $conn->prepare($query_users);
$statement_users->bindParam(':user_Email', $_POST['email']);
$statement_users->bindParam(':user_Name',$_POST['username']);
$statement_users->execute();
$count_users = $statement_users->rowCount();
if($count_users > 0){
$message = '<label class="text-danger">Email or user name Already Exits in users</label>';
}else{
$query_request = "SELECT * FROM registration_request WHERE email=:user_email OR user_name=:userName";
$statement_request = $conn->prepare($query_request);
$statement_request->bindParam(':user_email', $_POST['email']);
$statement_request->bindParam(':userName',$_POST['username']);
$statement_users->execute();
$count_request = $statement_request->rowCount();
if($count_request > 0){
$message = '<label class="text-danger">Email or user name Already Exits in registration request</label>';
}else{
// Enter the new user in the database
$user_activation_code = md5(rand());
$sql = "INSERT INTO registration_request (user_name,email, password,activation_code) VALUES (:user_name, :email, :password, :activation)";
$stmt = $conn->prepare($sql);
$encryptPass = password_hash($_POST['password'], PASSWORD_BCRYPT);
$stmt->bindParam(':user_name', $_POST['username']);
$stmt->bindParam(':email', $_POST['email']);
$stmt->bindParam(':password',$encryptPass);
$stmt->bindParam(':activation', $user_activation_code);
if( $stmt->execute() ){
//$message = 'Successfully created new user';
$base_url = getBaseUrl();
$mail_body = "<p>Hi ".$_POST['username'].",</p>
<p>Thanks for Registration. Your password is '".$_POST['password']."', This password will work only after your email verification.</p>
<p>Please Open this link to verified your email address - ".$base_url."email_verification.php?activation_code=".$user_activation_code."
<p>Best Regards,";
$to_email = $_POST["email"];
$from_email = $emailSetting["from_email"];//"info@local.test";
$subject = $emailSetting["reset_pass_mail_subject"];//"Email Verification";
require 'settings/mail/phpmailer/class/class.phpmailer.php';
$mail = new PHPMailer(true);
try {
$mail->IsSMTP(); //Sets Mailer to send message using SMTP
$mail->Host = $emailSetting["SMTP_host"]; //'localhost'; //Sets the SMTP hosts of your Email hosting, this for Godaddy
$mail->Port = $emailSetting["SMTP_port"]; //'25'; //Sets the default SMTP server port
$mail->SMTPAuth = ($emailSetting["SMTP_Auth"]=="1")?true:false; //false; //Sets SMTP authentication. Utilizes the Username and Password variables
$mail->Username = $emailSetting["SMTP_Username"]; //Sets SMTP username
$mail->Password = $emailSetting["SMTP_Password"]; //Sets SMTP password
$mail->SMTPSecure = $emailSetting["SMTP_Secure"]; //Sets connection prefix. Options are "", "ssl" or "tls"
$mail->From = $from_email;//'info@webslesson.info'; //Sets the From email address for the message
$mail->FromName = $emailSetting["from_name"];//'localhost'; //Sets the From name of the message
$mail->AddAddress($to_email, $_POST['username']); //Adds a "To" address
$mail->WordWrap = 400; //Sets word wrapping on the body of the message to a given number of characters
$mail->IsHTML(true); //Sets message type to HTML
$mail->Subject = $subject; //Sets the Subject of the message
$mail->Body = $mail_body; //An HTML or plain text message body
if($mail->Send()){ //Send an Email. Return true on success or false on error
$message = '<label class="text-success">Register Done, Please check your mail.</label>';
}else{
$message = "<label class='text-danger'>Email sending failed: " . $mail->ErrorInfo ." (phpmailer error)</label>";
$delRqstStt = deleteUserRequest($conn, $user_activation_code);
//$message .= " ($delRqstStt)";
}
}catch(phpmailerException $e) {
$message = "<label class='text-danger'>Email sending failed: ".$e->errorMessage()." (phpmailer error)</label>";
$delRqstStt = deleteUserRequest($conn, $user_activation_code);
//$message .= " ($delRqstStt)";
}catch(Exception $e) {
$message = "<label class='text-danger'>Email sending failed: " . $e->getMessage() ." (general error)</label>";
$delRqstStt = deleteUserRequest($conn, $user_activation_code);
//$message .= " ($delRqstStt)";
}
/*
if (mail($to_email, $subject, $mail_body, $headers)) {
$message = '<label class="text-success">Register Done, Please check your mail.</label>';
} else {
$message = '<label class="text-danger">Email sending failed...</label>';
}
*/
}else{
$message = '<label class="text-danger">Sorry there must have been an issue creating your account</label>';
}
}
}
}
function deleteUserRequest($conn, $user_activation_code){
$stt = "";
try {
$stmtDel = $conn->prepare("DELETE FROM registration_request WHERE activation_code = '$user_activation_code'");
$stmtDel->execute();
$stt = "success";
}catch(PDOException $e){
$stt = $e->getMessage();
}
return $stt;
}
function getBaseUrl(){
if(isset($_SERVER['HTTPS'])){
$protocol = ($_SERVER['HTTPS'] && $_SERVER['HTTPS'] != "off") ? "https" : "http";
}
else{
$protocol = 'http';
}
$host = $_SERVER['HTTP_HOST'];
$host_upper = strtoupper($host);
$path = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
return $protocol . "://" . $host . $path . "/";
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Register</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--===============================================================================================-->
<link rel="icon" type="image/png" href="images/icons/favicon.ico"/>
<!--===============================================================================================-->
<link rel="stylesheet" href="./include/bootstrap/css/bootstrap.min.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="./include/fonts/font-awesome-4.7.0/css/font-awesome.min.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="css/util.css">
<link rel="stylesheet" type="text/css" href="css/main.css">
<!--===============================================================================================-->
</head>
<body>
<?php if(!empty($message)): ?>
<p class=" p-t-20 p-b-20" style = "text-align:center;"><?= $message ?></p>
<?php endif; ?>
<div class="limiter">
<div class="container-login100" style="background-image: url('images/bg05.jpg');">
<div class="wrap-login100 p-b-100">
<h1>Register</h1>
<span>or <a href="login.php">login here</a></span>
<br>
<form class="login100-form validate-form" action="register.php" method="POST">
<span class="login100-form-title p-t-20 p-b-20">
</span>
<div class="wrap-input100 validate-input m-b-10" data-validate = "Enter your user name">
<input class="input100" type="text" name="username" placeholder="user name">
<span class="focus-input100"></span>
<span class="symbol-input100">
<i class="fa fa-user"></i>
</span>
</div>
<div class="wrap-input100 validate-input m-b-10" data-validate = "Enter your email (format: xxx@xxx.xxx)">
<input class="input100" type="text" name="email" placeholder="email">
<span class="focus-input100"></span>
<span class="symbol-input100">
<i class="fa fa-user"></i>
</span>
</div>
<div class="wrap-input100 validate-input m-b-10" data-validate = "password">
<input class="input100 main_password" type="password" name="password" placeholder="password">
<span class="focus-input100"></span>
<span class="symbol-input100">
<i class="fa fa-lock"></i>
</span>
</div>
<div class="wrap-input100 validate-input m-b-10" data-validate = "confirm password - Passwords Don't Match">
<input class="input100" type="password" name="confirm_password" placeholder="confirm password">
<span class="focus-input100"></span>
<span class="symbol-input100">
<i class="fa fa-lock"></i>
</span>
</div>
<div class="container-login100-form-btn p-t-10">
<input type="submit" class="login100-form-btn" value="submit" />
</div>
</form>
</div>
</div>
</div>
<!--===============================================================================================-->
<script src="./include/jquery/jquery-1.12.4.min.js"></script>
<!--===============================================================================================-->
<script src="js/main.js"></script>
</body>
</html>