1+ <?php
2+ require_once "pdo.php " ;
3+ require_once "head.php " ;
4+ date_default_timezone_set ('Asia/Taipei ' );
5+
6+ if (isset ($ _SESSION ["email " ])) {
7+ header ('Location: index.php ' );
8+ }
9+
10+ if (isset ($ _POST ["submit " ])) {
11+ $ statement = $ pdo ->prepare ("SELECT * FROM account where email = :em " );
12+ $ statement ->execute (array (':em ' => $ _POST ['email ' ]));
13+ $ response = $ statement ->fetch ();
14+
15+ if ($ response == "" ) {
16+ $ statement = $ pdo ->prepare ("SELECT * FROM account where username = :username " );
17+ $ statement ->execute (array (':username ' => $ _POST ['username ' ]));
18+ $ response = $ statement ->fetch ();
19+
20+ if ($ response == "" ) {
21+ $ username = $ _POST ['username ' ];
22+ $ email = $ _POST ['email ' ];
23+
24+ $ salt = getenv ('SALT ' );
25+ $ check = hash ("md5 " , $ salt . $ _POST ['password ' ]);
26+ $ password = $ check ;
27+
28+ $ stmt = $ pdo ->prepare ('INSERT INTO account
29+ (username, email, password) VALUES ( :username, :em, :pw) ' );
30+ $ stmt ->execute (
31+ array (
32+ ':username ' => $ username ,
33+ ':em ' => $ email ,
34+ ':pw ' => $ password
35+ )
36+ );
37+ $ ip = $ _SERVER ['HTTP_X_FORWARDED_FOR ' ];
38+ $ _SESSION ['success ' ] = "Account Created. Please login. " . " ip: " . $ ip ;
39+ header ('Location:login.php ' );
40+ } else {
41+ $ _SESSION ['error ' ] = "Username taken. " ;
42+ header ('Location:signup.php ' );
43+ }
44+ } else {
45+ $ _SESSION ['error ' ] = "Email taken. " ;
46+ header ('Location:signup.php ' );
47+ }
48+ return ;
49+ }
50+ ?>
51+
52+ <head>
53+ <title>Create Account</title>
54+ <style>
55+ html,
56+ body {
57+ height: 100%;
58+ background-color: #fff !important;
59+ }
60+
61+ body {
62+ display: -ms-flexbox;
63+ display: -webkit-box;
64+ display: flex;
65+ -ms-flex-align: center;
66+ -ms-flex-pack: center;
67+ -webkit-box-align: center;
68+ align-items: center;
69+ -webkit-box-pack: center;
70+ justify-content: center;
71+ padding-top: 40px;
72+ padding-bottom: 40px;
73+ background-color: #f5f5f5;
74+ }
75+
76+ .form-signin {
77+ width: 100%;
78+ max-width: 330px;
79+ padding: 15px;
80+ margin: 0 auto;
81+ }
82+
83+ .form-signin .checkbox {
84+ font-weight: 400;
85+ }
86+
87+ .form-signin .form-control {
88+ position: relative;
89+ box-sizing: border-box;
90+ height: auto;
91+ padding: 10px;
92+ font-size: 16px;
93+ }
94+
95+ .form-signin .form-control:focus {
96+ z-index: 2;
97+ }
98+
99+ .form-signin input[type="email"] {
100+ margin-bottom: -1px;
101+ border-bottom-right-radius: 0;
102+ border-bottom-left-radius: 0;
103+ }
104+
105+ .form-signin input[type="password"] {
106+ margin-bottom: 10px;
107+ border-top-left-radius: 0;
108+ border-top-right-radius: 0;
109+ }
110+ </style>
111+ </head>
112+ <form class="form-signin" method="post" action="./signup.php" enctype="multipart/form-data">
113+ <img class="mb-4" src="./favicon.ico" alt="" width="72" height="72">
114+ <h1 class="h3 mb-3 font-weight-normal">Signup</h1>
115+ <?php
116+ if (isset ($ _SESSION ["error " ])) {
117+ echo ('<p class="text-danger"> ' . htmlentities ($ _SESSION ["error " ]) . "</p> " );
118+ unset($ _SESSION ["error " ]);
119+ }
120+ if (isset ($ _SESSION ["success " ])) {
121+ echo ('<p class="text-success"> ' . htmlentities ($ _SESSION ["success " ]) . "</p> " );
122+ unset($ _SESSION ["success " ]);
123+ }
124+ ?>
125+ <label for="username" class="sr-only">Username</label>
126+ <input type="text" class="form-control" name="username" placeholder="Username" required="" autofocus="" maxlength=128>
127+ <label for="" class="sr-only">Email</label>
128+ <input type="email" id="id_email" class="form-control" name="email" placeholder="Email address" required="">
129+ <label for="inputPassword" class="sr-only">Password</label>
130+ <input type="password" id="id_1723" class="form-control" name="password" placeholder="Password" required="">
131+ <div class="checkbox mb-3">
132+ <label>
133+ <input type="checkbox" name="spamemail" value="spam my email"> Spam my email
134+ </label>
135+ </div>
136+ <button class="btn btn-lg btn-primary btn-block" name="submit" type="submit" onclick="return doValidate();">Signup</button>
137+ <br />Already have an account? please <a href="./login.php">log in</a>
138+ <p class="mt-5 mb-3 text-muted">© <?= date ("Y " ) ?> </p>
139+ By registering, you agree to our <a href="./terms-of-service.php" target="_blank">Terms</a>, <a href="./privacy-policy.php" target="_blank">Privacy Policy</a> and <a href="./cookie-policy.php" target="_blank">Cookie Policy</a>.<br />
140+ </form>
141+
142+ <script src="./particles/particles.js"></script>
143+ <script>
144+ function doValidate() {
145+ console.log("Validating...");
146+ try {
147+ email = document.getElementById("id_email").value;
148+ pw = document.getElementById("id_1723").value;
149+ console.log("Validating email=" + email);
150+ console.log("Validating pw=" + pw);
151+ if (pw == null || pw == "" || email == null || email == "") {
152+ alert("Both fields must be filled out");
153+ return false;
154+ }
155+ if (email.search("@") === -1) {
156+ alert("Email address must contain @");
157+ return false;
158+ }
159+ return true;
160+ } catch (e) {
161+ return false;
162+ }
163+ return false;
164+ }
165+ particlesJS.load('particles-js', './particles/particles.json', function() {
166+ console.log('callback - particles.js config loaded');
167+ });
168+ setTimeout(function() {
169+ document.querySelector('.popup-msg').style.display = "none";
170+ document.querySelector('.error').style.display = "none";
171+ }, 2200);
172+ </script>
0 commit comments