Added register functionality
This commit is contained in:
parent
d574a28c1d
commit
38af399ce9
|
|
@ -20,8 +20,20 @@ class User {
|
|||
|
||||
public function loginSubmit() {
|
||||
if ($_POST['username'] != '' && $_POST['password'] != '') {
|
||||
$user = $this->usersTable->find("username", $_POST['username'])[0];
|
||||
if (password_verify($_POST['password'], $user->password)) {
|
||||
$user = $this->usersTable->find("username", $_POST['username']);
|
||||
|
||||
if (count($user) > 0 && $_POST['submit'] == 'Register') {
|
||||
$this->vars['response'] = "Account already exists";
|
||||
}
|
||||
else if ($_POST['submit'] == "Register" && count($user) == 0) {
|
||||
$record = ['username' => $_POST['username'],
|
||||
'password' => password_hash($_POST['password'], PASSWORD_DEFAULT),
|
||||
'userType' => 'client'];
|
||||
$this->usersTable->save($record);
|
||||
$this->vars['response'] = 'You have now been registered';
|
||||
}
|
||||
else if ($_POST['submit'] == "Log In" && password_verify($_POST['password'], $user[0]->password)) {
|
||||
$user = $user[0];
|
||||
$_SESSION['loggedin'] = $user->id;
|
||||
$_SESSION['userType'] = $user->userType;
|
||||
$this->vars['response'] = 'You are now logged in';
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@
|
|||
<input type="password" name="password" />
|
||||
|
||||
<input type="submit" name="submit" value="Log In" />
|
||||
<input type="submit" name="submit" value="Register" />
|
||||
|
||||
</form>
|
||||
</main>
|
||||
<p><?=nl2br($response)?></p>
|
||||
|
|
|
|||
Loading…
Reference in New Issue