{"id":1151,"date":"2010-08-11T16:41:39","date_gmt":"2010-08-11T15:41:39","guid":{"rendered":"http:\/\/www.codingfriends.com\/?p=1151"},"modified":"2010-08-11T16:43:36","modified_gmt":"2010-08-11T15:43:36","slug":"cs71-ass1-finance-part-2-login-register-forgotten-password","status":"publish","type":"post","link":"https:\/\/www.codingfriends.com\/index.php\/2010\/08\/11\/cs71-ass1-finance-part-2-login-register-forgotten-password\/","title":{"rendered":"CS71 &#8211; Ass1 &#8211; Finance &#8211; Part 4 &#8211; Login Register Forgotten password"},"content":{"rendered":"<p><span id=\"zipfile\"><a href=\"http:\/\/www.codingfriends.com\/wp-content\/uploads\/2010\/08\/cs75-ass1.zip\"><\/a><\/span>I am doing the <a href=\"http:\/\/www.harvard.edu\/\">Harvards<\/a> building dynamic websites called <a href=\"http:\/\/www.cs75.net\/\">CS-75<\/a> (also could be called E-75), because someone told me about it and I just thought might as well, it is all learning \ud83d\ude42 even if allot of it you may already know.<\/p>\n<p>Since most of the work is done in the <a href=\"http:\/\/www.codingfriends.com\/index.php\/2010\/08\/11\/cs71-ass1-finance-part-2-classes\/\">class files<\/a>, from the previous post then we just use the classes to only have basic php pages for the user.  So the login page is just, which also has a check for if the user is already logged in and goto the viewdetails page, or if the user requests to logout then logout the user, the main page is just logging the user in.<\/p>\n<pre lang=\"php\">\r\n<?php\r\n\trequire(\"functions_start.php\");\r\n\t\r\n\tif (isset($_REQUEST[\"username\"]) &#038;&#038; isset($_REQUEST[\"password\"]))\r\n\t{\r\n\t\t$error = $theUser->LoginCheck($_REQUEST[\"username\"], $_REQUEST[\"password\"]);\r\n\t}\r\n\r\n\tif (isset($_REQUEST[\"logout\"]))\r\n\t\t$theUser->Logout();\r\n\r\n\tif (isset($_SESSION[\"authenticated\"]) && $_SESSION[\"authenticated\"]== true)\r\n\t{\r\n\t\theader(\"Location: \/viewdetails.php\");\r\n\t\texit;\r\n\t}\r\n\t\r\n\tHTMLHeader(\"Login to the stocks!\",false);\r\n\r\n\tif (isset($error))\r\n\t{\r\n\t\tif ($error==false)\r\n\t\t\techo \"<div>Not able to login, please try again<\/div>\";\r\n\t}\r\n\tif (isset($_REQUEST[\"logout\"])) \r\n\t\techo \"Thanks for using the site, you are logged out!\";\r\n?>\r\n<!-- taken from http:\/\/www.html.it\/articoli\/nifty\/index.html-->\r\n<div id=\"login\">\r\n<b class=\"rtop\">\r\n  <b class=\"r1\"><\/b> <b class=\"r2\"><\/b> <b class=\"r3\"><\/b> <b class=\"r4\"><\/b>\r\n<\/b>\r\n<form method=\"post\" action=\"<?php echo $_SERVER[\"PHP_SELF\"]; ?>\" onsubmit=\"\">\r\nLogin\r\n<p>\r\nUsername : <input type=\"text\" name=\"username\" id=\"username\" value=\"<?php echo $_REQUEST[\"username\"]; ?>\"\/>\r\n<\/p>\r\n<p>\r\nPassword : <input type=\"password\" name=\"password\" id=\"password\"\/>\r\n<\/p>\r\n<p>\r\n<input type=\"submit\"\/>\r\n<\/p>\r\n<p id=\"right\">\r\n<a href=\"register.php\">Register<\/a> here.\r\n<\/p>\r\n<\/form>\r\n<b class=\"rbottom\">\r\n  <b class=\"r4\"><\/b> <b class=\"r3\"><\/b> <b class=\"r2\"><\/b> <b class=\"r1\"><\/b>\r\n<\/b>\r\n<\/div>\r\n<?php\r\n\tHTMLFooter();\r\n?><\/pre>\n<p>Here is the register page, where I send the request to the users class and utilize the return value to display either a message of check your emails (or in this case it will be a link on the top of the page) or display a error to the user depending on what could happen, e.g. not a valid valid\/password(if the user turned off javascript checking) and also if there is already that email address present, the next check checks for the valid ID value that is sent to the user to validate there email.<\/p>\n<pre lang=\"php\">\r\n<?php\r\n\trequire(\"functions_start.php\");\r\n\t\r\n\tif (isset($_REQUEST[\"username\"]) &#038;&#038; isset($_REQUEST[\"password\"]))\r\n\t{\r\n\t\t$error = $theUser->RegisterUser($_REQUEST[\"username\"], $_REQUEST[\"password\"]);\r\n\t\tif ($error == -2)\r\n\t\t\t$notValidPassword = true;\r\n\t\telse if ($error == -1)\r\n\t\t\t$notValidEmail = true;\r\n\t\telse if ($error == 0)\r\n\t\t\t$emailAddressAlreadyPresent = true;\r\n\t\telse if ($error == 1)\r\n\t\t\t$checkEmails = true;\r\n\t}\r\n\r\n\tif (isset($_REQUEST[\"validid\"]) && isset($_REQUEST[\"uid\"]))\r\n\t{\r\n\t\t$error = $theUser->CheckUserGUID($_REQUEST[\"uid\"], $_REQUEST[\"validid\"]);\r\n\t\tif ($error == false)\r\n\t\t\t$userInvalid = true;\r\n\t\telse if ($error == true)\r\n\t\t{\t\t\t\r\n\t\t\t$theUser->LoginCheck($_REQUEST[\"uid\"],\"\",true);\r\n\t\t\theader(\"Location: \/viewdetails.php\");\r\n\t\t\texit;\r\n\t\t}\r\n\t}\r\n\t\r\n\tif (isset($_SESSION[\"authenticated\"]) && $_SESSION[\"authenticated\"]== true)\r\n\t{\r\n\t\theader(\"Location: \/viewdetails.php\");\r\n\t\texit;\r\n\t}\r\n\t\r\n\tHTMLHeader(\"Register\",false);\r\n\r\n\tif (isset($error))\r\n\t{\r\n\t\tif (isset($checkEmails))\r\n\t\t\techo \"<div>Please check your emails to validate your email address<\/div>\";\r\n\t\telse if (isset($notValidPassword))\r\n\t\t\techo \"<div id=\\\"error\\\">Not a valid password!, please enter one that is 6 characters and has at least 1 aphla\/numeric<\/div>\";\r\n\t\telse if (isset($emailAddressAlreadyPresent))\r\n\t\t\techo \"<div id=\\\"error\\\">Please use the forgotten password recovery,  already email address registered<\/div>\";\r\n\t\telse if (isset($notValidEmail))\r\n\t\t\techo \"<div id=\\\"error\\\">Not a valid email address<\/div>\";\r\n\t\telse if (isset($userInvalid))\r\n\t\t\techo \"<div id=\\\"error\\\">Does not validate correctly, please contact the system admin<\/div>\";\r\n\t}\r\n?>\r\n<!-- taken from http:\/\/www.html.it\/articoli\/nifty\/index.html-->\r\n<div id=\"login\">\r\n<b class=\"rtop\">\r\n  <b class=\"r1\"><\/b> <b class=\"r2\"><\/b> <b class=\"r3\"><\/b> <b class=\"r4\"><\/b>\r\n<\/b>\r\n<form method=\"post\" action=\"<?php echo $_SERVER[\"PHP_SELF\"]; ?>\" onsubmit=\"return CheckRegister()\">\r\nRegister <p>\r\nUsername : <input type=\"text\" name=\"username\" id=\"username\" value=\"<?php echo $_REQUEST[\"username\"]; ?>\"\/>\r\n(valid email address)<\/p>\r\n<p>\r\nPassword : <input type=\"password\" name=\"password\" id=\"password\"\/>\r\n(Has to be at least 6 characters and with 1 numeric and aplha character<\/p>\r\n<p>\r\n<input type=\"submit\"\/>\r\n<\/p>\r\n<\/form>\r\n<b class=\"rbottom\">\r\n  <b class=\"r4\"><\/b> <b class=\"r3\"><\/b> <b class=\"r2\"><\/b> <b class=\"r1\"><\/b>\r\n<\/b>\r\n<\/div>\r\n<?php\r\n\tHTMLFooter();\r\n?><\/pre>\n<p>Here is the last part, that will allow the user to enter there email to be able to get a link to enable them to change there password.<\/p>\n<pre lang=\"php\">\r\n<?php\r\n\trequire(\"functions_start.php\");\r\n\t\r\n\tif (isset($_REQUEST[\"username\"]) )\r\n\t{\r\n\t\t$error = $theUser->ForgottenUser($_REQUEST[\"username\"]);\r\n\t\tif ($error)\r\n\t\t\t$checkEmails = true;\r\n\t\telse \r\n\t\t\t$notValidEmail = true;\r\n\t}\r\n\r\n\tif (isset($_REQUEST[\"validid\"]) && isset($_REQUEST[\"uid\"]))\r\n\t{\r\n\t\t$error = $theUser->CheckUserGUID($_REQUEST[\"uid\"], $_REQUEST[\"validid\"]);\r\n\t\tif ($error == false)\r\n\t\t\t$userInvalid = true;\r\n\t\telse if ($error == true)\r\n\t\t{\t\t\t\r\n\t\t\t$theUser->LoginCheck($_REQUEST[\"uid\"],\"\",true);\r\n\t\t\theader(\"Location: \/changepassword.php\");\r\n\t\t\texit;\r\n\t\t}\r\n\t}\r\n\t\r\n\tif (isset($_SESSION[\"authenticated\"]) && $_SESSION[\"authenticated\"]== true)\r\n\t{\r\n\t\theader(\"Location: \/viewdetails.php\");\r\n\t\texit;\r\n\t}\r\n\t\r\n\tHTMLHeader(\"Forgotten password\",false);\r\n\r\n\tif (isset($error))\r\n\t{\r\n\t\tif (isset($checkEmails))\r\n\t\t\techo \"<div>Please check your emails to validate your email address<\/div>\";\r\n\t\telse if (isset($notValidEmail))\r\n\t\t\techo \"<div id=\\\"error\\\">Cannot find that email address<\/div>\";\r\n\t}\r\n?>\r\n<!-- taken from http:\/\/www.html.it\/articoli\/nifty\/index.html-->\r\n<div id=\"login\">\r\n<b class=\"rtop\">\r\n  <b class=\"r1\"><\/b> <b class=\"r2\"><\/b> <b class=\"r3\"><\/b> <b class=\"r4\"><\/b>\r\n<\/b>\r\n<form method=\"post\" action=\"<?php echo $_SERVER[\"PHP_SELF\"]; ?>\" onsubmit=\"return CheckRegister(true)\">\r\nForgotten password, please enter your username <p>\r\nUsername : <input type=\"text\" name=\"username\" id=\"username\" value=\"<?php echo $_REQUEST[\"username\"]; ?>\"\/>\r\n(valid email address)<\/p>\r\n<input type=\"submit\"\/>\r\n<\/p>\r\n<\/form>\r\n<b class=\"rbottom\">\r\n  <b class=\"r4\"><\/b> <b class=\"r3\"><\/b> <b class=\"r2\"><\/b> <b class=\"r1\"><\/b>\r\n<\/b>\r\n<\/div>\r\n<?php\r\n\tHTMLFooter();\r\n?><\/pre>\n<p>As you can see the actual pages are really simple because most of the work is done in the class files<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I am doing the Harvards building dynamic websites called CS-75 (also could be called E-75), because someone told me about it and I just thought might as well, it is all learning \ud83d\ude42 even if allot of it you may already know. Since most of the work is done in the class files, from the &hellip; <a href=\"https:\/\/www.codingfriends.com\/index.php\/2010\/08\/11\/cs71-ass1-finance-part-2-login-register-forgotten-password\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">CS71 &#8211; Ass1 &#8211; Finance &#8211; Part 4 &#8211; Login Register Forgotten password<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[246,249,271],"class_list":["post-1151","post","type-post","status-publish","format-standard","hentry","category-php","tag-assignment-1","tag-cs75","tag-finance"],"_links":{"self":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/1151","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/comments?post=1151"}],"version-history":[{"count":3,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/1151\/revisions"}],"predecessor-version":[{"id":1156,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/1151\/revisions\/1156"}],"wp:attachment":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/media?parent=1151"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/categories?post=1151"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/tags?post=1151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}