Guest User

Untitled

a guest
Oct 28th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.76 KB | None | 0 0
  1. <?php
  2. require_once 'dbconfig.php';
  3.  
  4. class USER
  5. {
  6.  
  7. private $conn;
  8.  
  9. public function __construct()
  10. {
  11. $database = new Database();
  12. $db = $database->dbConnection();
  13. $this->conn = $db;
  14. }
  15.  
  16. public function runQuery($sql)
  17. {
  18. $stmt = $this->conn->prepare($sql);
  19. return $stmt;
  20. }
  21.  
  22. public function lasdID()
  23. {
  24. $stmt = $this->conn->lastInsertId();
  25. return $stmt;
  26. }
  27.  
  28. public function register($uname,$email,$upass,$code)
  29. {
  30. try
  31. {
  32. $password = md5($upass);
  33. $stmt = $this->conn->prepare("INSERT INTO tbl_users(userName,userEmail,userPass,tokenCode)
  34. VALUES(:user_name, :user_mail, :user_pass, :active_code)");
  35. $stmt->bindparam(":user_name",$uname);
  36. $stmt->bindparam(":user_mail",$email);
  37. $stmt->bindparam(":user_pass",$password);
  38. $stmt->bindparam(":active_code",$code);
  39. $stmt->execute();
  40. return $stmt;
  41. }
  42. catch(PDOException $ex)
  43. {
  44. echo $ex->getMessage();
  45. }
  46. }
  47.  
  48. public function login($email,$upass)
  49. {
  50. try
  51. {
  52. $stmt = $this->conn->prepare("SELECT * FROM tbl_users WHERE userEmail=:email_id");
  53. $stmt->execute(array(":email_id"=>$email));
  54. $userRow=$stmt->fetch(PDO::FETCH_ASSOC);
  55.  
  56. if($stmt->rowCount() == 1)
  57. {
  58. if($userRow['userStatus']=="Y")
  59. {
  60. if($userRow['userPass']==md5($upass))
  61. {
  62. $_SESSION['userSession'] = $userRow['userID'];
  63. return true;
  64. }
  65. else
  66. {
  67. header("Location: index.php?error");
  68. exit;
  69. }
  70. }
  71. else
  72. {
  73. header("Location: index.php?inactive");
  74. exit;
  75. }
  76. }
  77. else
  78. {
  79. header("Location: index.php?error");
  80. exit;
  81. }
  82. }
  83. catch(PDOException $ex)
  84. {
  85. echo $ex->getMessage();
  86. }
  87. }
  88.  
  89.  
  90. public function is_logged_in()
  91. {
  92. if(isset($_SESSION['userSession']))
  93. {
  94. return true;
  95. }
  96. }
  97.  
  98. public function redirect($url)
  99. {
  100. header("Location: $url");
  101. }
  102.  
  103. public function logout()
  104. {
  105. session_destroy();
  106. $_SESSION['userSession'] = false;
  107. }
  108.  
  109. function send_mail($email,$message,$subject)
  110. {
  111. require_once('mailer/class.phpmailer.php');
  112. $mail = new PHPMailer();
  113. $mail->IsSMTP();
  114. $mail->SMTPDebug = 0;
  115. $mail->SMTPAuth = true;
  116. $mail->SMTPSecure = "ssl";
  117. $mail->Host = "smtp.yandex.ru";
  118. $mail->Port = 465;
  119. $mail->AddAddress($email);
  120. $mail->Username="mail";
  121. $mail->Password="pass";
  122. $mail->SetFrom('name','Coding Cage');
  123. $mail->AddReplyTo("name","Coding Cage");
  124. $mail->Subject = $subject;
  125. $mail->MsgHTML($message);
  126. $mail->Send();
  127. }
  128. }
  129. ?>
  130.  
  131. <?php
  132. session_start();
  133. require_once 'class.user.php';
  134.  
  135. $reg_user = new USER();
  136.  
  137. if($reg_user->is_logged_in()!="")
  138. {
  139. $reg_user->redirect('home.php');
  140. }
  141.  
  142.  
  143. if(isset($_POST['btn-signup']))
  144. {
  145. $uname = trim($_POST['txtuname']);
  146. $email = trim($_POST['txtemail']);
  147. $upass = trim($_POST['txtpass']);
  148. $code = md5(uniqid(rand()));
  149.  
  150. $stmt = $reg_user->runQuery("SELECT * FROM tbl_users WHERE userEmail=:email_id");
  151. $stmt->execute(array(":email_id"=>$email));
  152. $row = $stmt->fetch(PDO::FETCH_ASSOC);
  153.  
  154. if($stmt->rowCount() > 0)
  155. {
  156. $msg = "
  157. <div class='alert alert-error'>
  158. <button class='close' data-dismiss='alert'>&times;</button>
  159. <strong>Sorry !</strong> email allready exists , Please Try another one
  160. </div>
  161. ";
  162. }
  163. else
  164. {
  165. if($reg_user->register($uname,$email,$upass,$code))
  166. {
  167. $id = $reg_user->lasdID();
  168. $key = base64_encode($id);
  169. $id = $key;
  170.  
  171. $message = "
  172. Hello $uname,
  173. <br /><br />
  174. Welcome to Coding Cage!<br/>
  175. To complete your registration please , just click following link<br/>
  176. <br /><br />
  177. <a href='http://vh159953.eurodir.ru/test/verify.php?id=$id&code=$code'>Click HERE to Activate :)</a>
  178. <br /><br />
  179. Thanks,";
  180.  
  181. $subject = "Confirm Registration";
  182.  
  183. $reg_user->send_mail($email,$message,$subject);
  184. $msg = "
  185. <div class='alert alert-success'>
  186. <button class='close' data-dismiss='alert'>&times;</button>
  187. <strong>Success!</strong> We've sent an email to $email.
  188. Please click on the confirmation link in the email to create your account.
  189. </div>
  190. ";
  191. }
  192. else
  193. {
  194. echo "sorry , Query could no execute...";
  195. }
  196. }
  197. }
  198. ?>
  199. <!DOCTYPE html>
  200. <html>
  201. <head>
  202. <title>Signup | Coding Cage</title>
  203. <!-- Bootstrap -->
  204. <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
  205. <link href="bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen">
  206. <link href="assets/styles.css" rel="stylesheet" media="screen">
  207. <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
  208. <!--[if lt IE 9]>
  209. <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
  210. <![endif]-->
  211. <script src="js/vendor/modernizr-2.6.2-respond-1.1.0.min.js"></script>
  212. </head>
  213. <body id="login">
  214. <div class="container">
  215. <?php if(isset($msg)) echo $msg; ?>
  216. <form class="form-signin" method="post">
  217. <h2 class="form-signin-heading">Sign Up</h2><hr />
  218. <input type="text" class="input-block-level" placeholder="Username" name="txtuname" required />
  219. <input type="email" class="input-block-level" placeholder="Email address" name="txtemail" required />
  220. <input type="password" class="input-block-level" placeholder="Password" name="txtpass" required />
  221. <hr />
  222. <button class="btn btn-large btn-primary" type="submit" name="btn-signup">Sign Up</button>
  223. <a href="index.php" style="float:right;" class="btn btn-large">Sign In</a>
  224. </form>
  225.  
  226. </div> <!-- /container -->
  227. <script src="vendors/jquery-1.9.1.min.js"></script>
  228. <script src="bootstrap/js/bootstrap.min.js"></script>
  229. </body>
  230. </html>
  231.  
  232. <?php
  233. require_once 'class.user.php';
  234. $user = new USER();
  235.  
  236. if(empty($_GET['id']) && empty($_GET['code']))
  237. {
  238. $user->redirect('index.php');
  239. }
  240.  
  241. if(isset($_GET['id']) && isset($_GET['code']))
  242. {
  243. $id = base64_decode($_GET['id']);
  244. $code = $_GET['code'];
  245.  
  246. $statusY = "Y";
  247. $statusN = "N";
  248.  
  249. $stmt = $user->runQuery("SELECT userID,userStatus FROM tbl_users WHERE userID=:uID AND tokenCode=:code LIMIT 1");
  250. $stmt->execute(array(":uID"=>$id,":code"=>$code));
  251. $row=$stmt->fetch(PDO::FETCH_ASSOC);
  252. if($stmt->rowCount() > 0)
  253. {
  254. if($row['userStatus']==$statusN)
  255. {
  256. $stmt = $user->runQuery("UPDATE tbl_users SET userStatus=:status WHERE userID=:uID");
  257. $stmt->bindparam(":status",$statusY);
  258. $stmt->bindparam(":uID",$id);
  259. $stmt->execute();
  260.  
  261. $msg = "
  262. <div class='alert alert-success'>
  263. <button class='close' data-dismiss='alert'>&times;</button>
  264. <strong>WoW !</strong> Your Account is Now Activated : <a href='index.php'>Login here</a>
  265. </div>
  266. ";
  267. }
  268. else
  269. {
  270. $msg = "
  271. <div class='alert alert-error'>
  272. <button class='close' data-dismiss='alert'>&times;</button>
  273. <strong>sorry !</strong> Your Account is allready Activated : <a href='index.php'>Login here</a>
  274. </div>
  275. ";
  276. }
  277. }
  278. else
  279. {
  280. $msg = "
  281. <div class='alert alert-error'>
  282. <button class='close' data-dismiss='alert'>&times;</button>
  283. <strong>sorry !</strong> No Account Found : <a href='signup.php'>Signup here</a>
  284. </div>
  285. ";
  286. }
  287. }
  288.  
  289. ?>
  290. <!DOCTYPE html>
  291. <html>
  292. <head>
  293. <title>Confirm Registration</title>
  294. <!-- Bootstrap -->
  295. <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
  296. <link href="bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen">
  297. <link href="assets/styles.css" rel="stylesheet" media="screen">
  298. <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
  299. <!--[if lt IE 9]>
  300. <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
  301. <![endif]-->
  302. <script src="js/vendor/modernizr-2.6.2-respond-1.1.0.min.js"></script>
  303. </head>
  304. <body id="login">
  305. <div class="container">
  306. <?php if(isset($msg)) { echo $msg; } ?>
  307. </div> <!-- /container -->
  308. <script src="vendors/jquery-1.9.1.min.js"></script>
  309. <script src="bootstrap/js/bootstrap.min.js"></script>
  310. </body>
  311. </html>
  312.  
  313. <?php
  314. session_start();
  315. require_once 'class.user.php';
  316. $user_login = new USER();
  317.  
  318. if($user_login->is_logged_in()!="")
  319. {
  320. $user_login->redirect('home.php');
  321. }
  322.  
  323. if(isset($_POST['btn-login']))
  324. {
  325. $email = trim($_POST['txtemail']);
  326. $upass = trim($_POST['txtupass']);
  327.  
  328. if($user_login->login($email,$upass))
  329. {
  330. $user_login->redirect('home.php');
  331. }
  332. }
  333. ?>
  334.  
  335. <!DOCTYPE html>
  336. <html>
  337. <head>
  338. <title>Login | Coding Cage</title>
  339. <!-- Bootstrap -->
  340. <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
  341. <link href="bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen">
  342. <link href="assets/styles.css" rel="stylesheet" media="screen">
  343. <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
  344. <!--[if lt IE 9]>
  345. <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
  346. <![endif]-->
  347. <script src="js/vendor/modernizr-2.6.2-respond-1.1.0.min.js"></script>
  348. </head>
  349. <body id="login">
  350. <div class="container">
  351. <?php
  352. if(isset($_GET['inactive']))
  353. {
  354. ?>
  355. <div class='alert alert-error'>
  356. <button class='close' data-dismiss='alert'>&times;</button>
  357. <strong>Sorry!</strong> This Account is not Activated Go to your Inbox and Activate it.
  358. </div>
  359. <?php
  360. }
  361. ?>
  362. <form class="form-signin" method="post">
  363. <?php
  364. if(isset($_GET['error']))
  365. {
  366. ?>
  367. <div class='alert alert-success'>
  368. <button class='close' data-dismiss='alert'>&times;</button>
  369. <strong>Wrong Details!</strong>
  370. </div>
  371. <?php
  372. }
  373. ?>
  374. <h2 class="form-signin-heading">Sign In.</h2><hr />
  375. <input type="email" class="input-block-level" placeholder="Email address" name="txtemail" required />
  376. <input type="password" class="input-block-level" placeholder="Password" name="txtupass" required />
  377. <hr />
  378. <button class="btn btn-large btn-primary" type="submit" name="btn-login">Sign in</button>
  379. <a href="signup.php" style="float:right;" class="btn btn-large">Sign Up</a><hr />
  380. <a href="fpass.php">Lost your Password ? </a>
  381. </form>
  382.  
  383. </div> <!-- /container -->
  384. <script src="bootstrap/js/jquery-1.9.1.min.js"></script>
  385. <script src="bootstrap/js/bootstrap.min.js"></script>
  386. </body>
  387. </html>
  388.  
  389. <?php
  390. session_start();
  391. require_once 'class.user.php';
  392. $user_home = new USER();
  393.  
  394. if(!$user_home->is_logged_in())
  395. {
  396. $user_home->redirect('index.php');
  397. }
  398.  
  399. $stmt = $user_home->runQuery("SELECT * FROM tbl_users WHERE userID=:uid");
  400. $stmt->execute(array(":uid"=>$_SESSION['userSession']));
  401. $row = $stmt->fetch(PDO::FETCH_ASSOC);
  402.  
  403. ?>
  404.  
  405. <!DOCTYPE html>
  406. <html class="no-js">
  407.  
  408. <head>
  409. <title><?php echo $row['userEmail']; ?></title>
  410. <!-- Bootstrap -->
  411. <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
  412. <link href="bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen">
  413. <link href="assets/styles.css" rel="stylesheet" media="screen">
  414. <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
  415. <!--[if lt IE 9]>
  416. <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
  417. <![endif]-->
  418.  
  419. </head>
  420.  
  421. <body>
  422. <div class="navbar navbar-fixed-top">
  423. <div class="navbar-inner">
  424. <div class="container-fluid">
  425. <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse"> <span class="icon-bar"></span>
  426. <span class="icon-bar"></span>
  427. <span class="icon-bar"></span>
  428. </a>
  429. <a class="brand" href="#">Member Home</a>
  430. <div class="nav-collapse collapse">
  431. <ul class="nav pull-right">
  432. <li class="dropdown">
  433. <a href="#" role="button" class="dropdown-toggle" data-toggle="dropdown"> <i class="icon-user"></i>
  434. <?php echo $row['userEmail']; ?> <i class="caret"></i>
  435. </a>
  436. <ul class="dropdown-menu">
  437. <li>
  438. <a tabindex="-1" href="logout.php">Logout</a>
  439. </li>
  440. </ul>
  441. </li>
  442. </ul>
  443. <ul class="nav">
  444. <li class="active">
  445. <a href="http://www.codingcage.com/">Coding Cage</a>
  446. </li>
  447. <li class="dropdown">
  448. <a href="#" data-toggle="dropdown" class="dropdown-toggle">Tutorials <b class="caret"></b>
  449.  
  450. </a>
  451. <ul class="dropdown-menu" id="menu1">
  452. <li><a href="http://www.codingcage.com/search/label/PHP OOP">PHP OOP</a></li>
  453. <li><a href="http://www.codingcage.com/search/label/PDO">PHP PDO</a></li>
  454. <li><a href="http://www.codingcage.com/search/label/jQuery">jQuery</a></li>
  455. <li><a href="http://www.codingcage.com/search/label/Bootstrap">Bootstrap</a></li>
  456. <li><a href="http://www.codingcage.com/search/label/CRUD">CRUD</a></li>
  457. </ul>
  458. </li>
  459. <li>
  460. <a href="http://www.codingcage.com/2015/09/login-registration-email-verification-forgot-password-php.html">Tutorial Link</a>
  461. </li>
  462.  
  463.  
  464. </ul>
  465. </div>
  466. <!--/.nav-collapse -->
  467. </div>
  468. </div>
  469. </div>
  470.  
  471. <!--/.fluid-container-->
  472. <script src="bootstrap/js/jquery-1.9.1.min.js"></script>
  473. <script src="bootstrap/js/bootstrap.min.js"></script>
  474. <script src="assets/scripts.js"></script>
  475.  
  476. </body>
  477.  
  478. </html>
Add Comment
Please, Sign In to add comment