Created
February 14, 2020 14:40
-
-
Save jacmaes/93e22d6d3aa34ee67c351cc05629d290 to your computer and use it in GitHub Desktop.
PW user login #pw #php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// From Kreativan's gist: https://gist.github.com/kreativan/4f58bf3a8f35cc307ef2effe3a27086d | |
<?php | |
// logout | |
if($input->get->logout) { | |
$session->logout(); | |
$session->redirect($page->url); | |
} | |
// login user | |
if($input->post->login) { | |
try { | |
$email = $sanitizer->email($input->post->email); | |
$psw = $sanitizer->text($input->post->psw); | |
$user_name = $users->get("email=$email")->name; | |
$u = $session->login($user_name, $psw); | |
if($u && $u->id){ | |
$session->redirect($page->url); | |
} else { | |
$alert = "<div class='uk-alert uk-alert-danger'>Login faild</div>"; | |
} | |
} catch (\Exception $e) { | |
$alert = $e->getMessage(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment