Merge pull request #143 from ThomasRubini/user_time

This commit is contained in:
Thomas Rubini 2023-01-26 20:10:29 +01:00 committed by GitHub
commit 6c571f3a62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -7,6 +7,10 @@ ini_set("session.cookie_lifetime", $__SESSION_TIMEOUT);
final class UserController
{
private static function currentDate(){
return date("Y-m-d H:i:s");
}
public function loginAction(Array $A_urlParams = null, Array $A_postParams = null, Array $A_getParams = null)
{
if (Session::is_login()) {
@ -53,6 +57,9 @@ final class UserController
return header("Location: /user/login");
}
$O_user->S_LAST_SEEN = self::currentDate();
$O_user->update();
Session::set_login($O_user->I_ID);
self::redirectToPreviousPage($A_postParams);
@ -81,7 +88,7 @@ final class UserController
$S_password_hash = password_hash($S_password, PASSWORD_DEFAULT);
$O_user = new UserModel($S_email, $S_username, $S_password_hash, null, date("Y-m-d"), 0, 0);
$O_user = UserModel::createFull($S_email, $S_username, $S_password_hash, self::currentDate(), self::currentDate(), 0, 0);
$O_user->insert();
Session::set_login($O_user->I_ID);

View File

@ -45,10 +45,11 @@ final class UserModel extends UserSessionModel
public function insert(){
$O_model = Model::get();
$stmt = $O_model->prepare("INSERT INTO USER (EMAIL, USERNAME, PASS_HASH, FIRST_SEEN) VALUES(:email, :username, :password_hash, :first_seen)");
$stmt = $O_model->prepare("INSERT INTO USER (EMAIL, USERNAME, PASS_HASH, FIRST_SEEN, LAST_SEEN) VALUES(:email, :username, :password_hash, :first_seen, :last_seen)");
$stmt->bindParam("email", $this->S_EMAIL);
$stmt->bindParam("username", $this->S_USERNAME);
$stmt->bindParam("password_hash", $this->S_PASSWORD_HASH);
$stmt->bindParam("last_seen", $this->S_LAST_SEEN);
$stmt->bindParam("first_seen", $this->S_FIRST_SEEN);
$stmt->execute();
$this->I_ID = Model::get()->lastInsertId();