Advertisement
Guest User

Untitled

a guest
Jul 1st, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.34 KB | None | 0 0
  1. <?php require('includes/config.php');
  2.  
  3. //if logged in redirect to members page
  4. if( $user->is_logged_in() ){ header('Location: memberpage.php'); }
  5.  
  6. //if form has been submitted process it
  7. if(isset($_POST['submit'])){
  8.  
  9. //very basic validation
  10. if(strlen($_POST['username']) < 3){
  11. $error[] = 'Username is too short.';
  12. } else {
  13. $stmt = $db->prepare('SELECT username FROM members WHERE username = :username');
  14. $stmt->execute(array(':username' => $_POST['username']));
  15. $row = $stmt->fetch(PDO::FETCH_ASSOC);
  16.  
  17. if(!empty($row['username'])){
  18. $error[] = 'Username provided is already in use.';
  19. }
  20.  
  21. }
  22.  
  23. if(strlen($_POST['password']) < 3){
  24. $error[] = 'Password is too short.';
  25. }
  26.  
  27. if(strlen($_POST['passwordConfirm']) < 3){
  28. $error[] = 'Confirm password is too short.';
  29. }
  30.  
  31. if($_POST['password'] != $_POST['passwordConfirm']){
  32. $error[] = 'Passwords do not match.';
  33. }
  34.  
  35. //email validation
  36. if(!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)){
  37. $error[] = 'Please enter a valid email address';
  38. } else {
  39. $stmt = $db->prepare('SELECT email FROM members WHERE email = :email');
  40. $stmt->execute(array(':email' => $_POST['email']));
  41. $row = $stmt->fetch(PDO::FETCH_ASSOC);
  42.  
  43. if(!empty($row['email'])){
  44. $error[] = 'Email provided is already in use.';
  45. }
  46.  
  47. }
  48.  
  49.  
  50. //if no errors have been created carry on
  51. if(!isset($error)){
  52.  
  53. //hash the password
  54. $hashedpassword = $user->password_hash($_POST['password'], PASSWORD_BCRYPT);
  55.  
  56. //create the activasion code
  57. $activasion = md5(uniqid(rand(),true));
  58.  
  59. try {
  60.  
  61. //insert into database with a prepared statement
  62. $stmt = $db->prepare('INSERT INTO members (username,password,email,active) VALUES (:username, :password, :email, :active)');
  63. $stmt->execute(array(
  64. ':username' => $_POST['username'],
  65. ':password' => $hashedpassword,
  66. ':email' => $_POST['email'],
  67. ':active' => $activasion
  68. ));
  69. $id = $db->lastInseratId('memberID');
  70.  
  71. //send email
  72. $to = $_POST['email'];
  73. $subject = "Registration Confirmation";
  74. $body = "<p>Thank you for registering at demo site.</p>
  75. <p>To activate your account, please click on this link: <a href='".DIR."activate.php?x=$id&y=$activasion'>".DIR."activate.php?x=$id&y=$activasion</a></p>
  76. <p>Regards Site Admin</p>";
  77.  
  78. $mail = new Mail();
  79. $mail->setFrom(SITEEMAIL);
  80. $mail->addAddress($to);
  81. $mail->subject($subject);
  82. $mail->body($body);
  83. $mail->send();
  84.  
  85. //redirect to index page
  86. header('Location: index.php?action=joined');
  87. exit;
  88.  
  89. //else catch the exception and show the error.
  90. } catch(PDOException $e) {
  91. $error[] = $e->getMessage();
  92. }
  93.  
  94. }
  95.  
  96. }
  97.  
  98. ?>
  99.  
  100. <!DOCTYPE html>
  101. <html lang="en">
  102. <head>
  103. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  104. <meta charset="utf-8" />
  105. <title>New User Registration</title>
  106.  
  107. <meta name="description" content="User login page" />
  108. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
  109.  
  110. <!-- bootstrap & fontawesome -->
  111. <link rel="stylesheet" href="assets/css/bootstrap.min.css" />
  112. <link rel="stylesheet" href="assets/font-awesome/4.2.0/css/font-awesome.min.css" />
  113.  
  114. <!-- text fonts -->
  115. <link rel="stylesheet" href="assets/fonts/fonts.googleapis.com.css" />
  116.  
  117. <!-- ace styles -->
  118. <link rel="stylesheet" href="assets/css/ace.min.css" />
  119.  
  120. <!--[if lte IE 9]>
  121. <link rel="stylesheet" href="assets/css/ace-part2.min.css" />
  122. <![endif]-->
  123. <link rel="stylesheet" href="assets/css/ace-rtl.min.css" />
  124.  
  125. <!--[if lte IE 9]>
  126. <link rel="stylesheet" href="assets/css/ace-ie.min.css" />
  127. <![endif]-->
  128.  
  129. <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
  130.  
  131. <!--[if lt IE 9]>
  132. <script src="assets/js/html5shiv.min.js"></script>
  133. <script src="assets/js/respond.min.js"></script>
  134. <![endif]-->
  135. </head>
  136. <body class="login-layout">
  137. <div class="main-container">
  138. <div class="main-content">
  139. <div class="row">
  140. <div class="col-sm-10 col-sm-offset-1">
  141. <div class="login-container">
  142. <div class="center">
  143. <h1>
  144. <i class="ace-icon fa fa-leaf green"></i>
  145. <span class="red">Ace</span>
  146. <span class="white" id="id-text2">Application</span>
  147. </h1>
  148. <h4 class="blue" id="id-company-text">&copy; Company Name</h4>
  149. </div>
  150.  
  151. <div class="space-6"></div>
  152.  
  153. <div class="position-relative">
  154.  
  155. <div id="signup-box" class="signup-box widget-box no-border visible">
  156. <div class="widget-body">
  157. <div class="widget-main">
  158. <h4 class="header green lighter bigger">
  159. <i class="ace-icon fa fa-users blue"></i>
  160. New User Registration
  161. </h4>
  162.  
  163. <div class="space-6"></div>
  164. <p> Enter your details to begin: </p>
  165.  
  166. <form role="form" method="post" action="" autocomplete="off">
  167. <?php
  168. //check for any errors
  169. if(isset($error)){
  170. foreach($error as $error){
  171. echo '<p class="bg-danger">'.$error.'</p>';
  172. }
  173. }
  174.  
  175. //if action is joined show sucess
  176. if(isset($_GET['action']) && $_GET['action'] == 'joined'){
  177. echo "<h2 class='bg-success'>Registration successful, please check your email to activate your account.</h2>";
  178. }
  179. ?>
  180. <fieldset>
  181. <label class="block clearfix">
  182. <span class="block input-icon input-icon-right">
  183. <input type="email" name="email" id="email" class="form-control" placeholder="Email" value="<?php if(isset($error)){ echo $_POST['email']; } ?>" tabindex="1">
  184. <i class="ace-icon fa fa-envelope"></i>
  185. </span>
  186. </label>
  187.  
  188. <label class="block clearfix">
  189. <span class="block input-icon input-icon-right">
  190. <input type="text" name="username" id="username" class="form-control" placeholder="Username" value="<?php if(isset($error)){ echo $_POST['username']; } ?>" tabindex="2">
  191. <i class="ace-icon fa fa-user"></i>
  192. </span>
  193. </label>
  194.  
  195. <label class="block clearfix">
  196. <span class="block input-icon input-icon-right">
  197. <input type="password" name="password" id="password" class="form-control" placeholder="Password" tabindex="3">
  198. <i class="ace-icon fa fa-lock"></i>
  199. </span>
  200. </label>
  201.  
  202. <label class="block clearfix">
  203. <span class="block input-icon input-icon-right">
  204. <input type="password" name="passwordConfirm" id="passwordConfirm" class="form-control" placeholder="Confirm password" tabindex="4">
  205. <i class="ace-icon fa fa-retweet"></i>
  206. </span>
  207. </label>
  208.  
  209. <label class="block">
  210. <input type="checkbox" class="ace">
  211. <span class="lbl">
  212. I accept the
  213. <a href="#">User Agreement</a>
  214. </span>
  215. </label>
  216.  
  217. <div class="space-24"></div>
  218.  
  219. <div class="clearfix">
  220. <button type="reset" class="width-30 pull-left btn btn-sm">
  221. <i class="ace-icon fa fa-refresh"></i>
  222. <span class="bigger-110">Reset</span>
  223. </button>
  224.  
  225. <button type="submit" name="submit" class="width-65 pull-right btn btn-sm btn-success" tabindex="5">
  226. <span class="bigger-110">Register</span>
  227.  
  228. <i class="ace-icon fa fa-arrow-right icon-on-right"></i>
  229. </button>
  230. </div>
  231. </fieldset>
  232. </form>
  233. </div>
  234.  
  235. <div class="toolbar center">
  236. <a href="login.html" class="back-to-login-link">
  237. <i class="ace-icon fa fa-arrow-left"></i>
  238. Back to login
  239. </a>
  240. </div>
  241. </div><!-- /.widget-body -->
  242. </div><!-- /.signup-box -->
  243. </div><!-- /.position-relative -->
  244.  
  245. </div>
  246. </div><!-- /.col -->
  247. </div><!-- /.row -->
  248. </div><!-- /.main-content -->
  249. </div><!-- /.main-container -->
  250.  
  251. <!-- basic scripts -->
  252.  
  253. <!--[if !IE]> -->
  254. <script src="assets/js/jquery.2.1.1.min.js"></script>
  255.  
  256. <!-- <![endif]-->
  257.  
  258. <!--[if IE]>
  259. <script src="assets/js/jquery.1.11.1.min.js"></script>
  260. <![endif]-->
  261.  
  262. <!--[if !IE]> -->
  263. <script type="text/javascript">
  264. window.jQuery || document.write("<script src='assets/js/jquery.min.js'>"+"<"+"/script>");
  265. </script>
  266.  
  267. <!-- <![endif]-->
  268.  
  269. <!--[if IE]>
  270. <script type="text/javascript">
  271. window.jQuery || document.write("<script src='assets/js/jquery1x.min.js'>"+"<"+"/script>");
  272. </script>
  273. <![endif]-->
  274. <script type="text/javascript">
  275. if('ontouchstart' in document.documentElement) document.write("<script src='assets/js/jquery.mobile.custom.min.js'>"+"<"+"/script>");
  276. </script>
  277.  
  278. </body>
  279. </html>
  280.  
  281. ****----------------Here is my Mail.php file-------------------****
  282. <?php
  283. include('phpmailer.php');
  284. class Mail extends PhpMailer
  285. {
  286. // Set default variables for all new objects
  287. public $From = 'noreply@domain.com';
  288. public $FromName = SITETITLE;
  289. public $Host = 'smtp.gmail.com';
  290. public $Mailer = 'isSMTP';
  291. public $SMTPAuth = true;
  292. public $Username = 'email@gmail.com';
  293. public $Password = 'password';
  294. public $SMTPSecure = 'ssl';
  295. public $WordWrap = 75;
  296.  
  297. public function subject($subject)
  298. {
  299. $this->Subject = $subject;
  300. }
  301.  
  302. public function body($body)
  303. {
  304. $this->Body = $body;
  305. }
  306.  
  307. public function send()
  308. {
  309. $this->AltBody = strip_tags(stripslashes($this->Body))."nn";
  310. $this->AltBody = str_replace("&nbsp;", "nn", $this->AltBody);
  311. return parent::send();
  312. }
  313. }
  314.  
  315. [1]: http://i.stack.imgur.com/MUOEy.png Email Inbox Screenshot
  316.  
  317. header('Location:index.php?action=joined');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement