| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- <?php
- class User {
- private $id = null;
- private $mail = null;
- private $admin = null;
- public function __construct($mail) {
- $user = $GLOBALS['db']->getAllAssoc("users", "mail", $mail);
- $this->id = $user[0]['id'];
- $this->mail = $user[0]['mail'];
- $this->admin = $user[0]['admin'];
- }
- public static function login($request) {
- $hashedPass = $GLOBALS['db']->getString("pass", "users", "mail", $request['mail']);
- if($hashedPass == md5($request['pass'])) {
- $_SESSION['loggedIn'] = true;
- $_SESSION['mail'] = $request['mail'];
- header("Location: /");
- } else {
- echo "PW mismatch, try again.";
- exit(1);
- }
- }
- public static function logout() {
- session_destroy();
- header("Location: /");
- }
- public static function update($newPassword, $newPasswordConfirmation, $newEmail, $oldEmail, $logout = true) {
- if($newPassword && $newPasswordConfirmation) {
- if($newPassword == $newPasswordConfirmation) {
- $GLOBALS['db']->updateRow("users", "pass", "MD5('" . $newPassword . "')", "id", Model::getUserIDByMail($oldEmail)[0]['id']);
- } else {
- return "Passwords don't match.";
- }
- }
- $GLOBALS['db']->updateRow("users", "mail", "'" . $newEmail . "'", "id", Model::getUserIDByMail($oldEmail)[0]['id']);
- if($logout) {
- User::logout();
- }
- }
- public static function invite($email) {
- $password = generatePassword();
- $invite = generatePassword(16);
- $cols = array(
- "mail",
- "pass"
- );
- $vals = array(
- $email,
- $password,
- );
- $GLOBALS['db']->insertRow("users", $cols, $vals);
- self::update($password, $password, $email, $email, false);
- $msg = 'Was geht,' . PHP_EOL . "Hier deine Accountdaten:" . PHP_EOL . "Email: Diese Email-Adresse" . PHP_EOL . "Passwort: " . $password . PHP_EOL . "PW bitte ändern!";
- mail($email, "Moeflix invite", $msg, 'From: moritz+moeflix@mmnx.de');
- }
- /**
- * Get the value of Id
- *
- *
- * @return mixed
- *
- */
- public function getId() {
- return $this->id;
- }
- /**
- * Set the value of Id
- *
- *
- * @param mixed id
- *
- */
- public function setId($id) {
- $this->id = $id;
- }
- /**
- * Get the value of Mail
- *
- *
- * @return mixed
- *
- */
- public function getMail() {
- return $this->mail;
- }
- /**
- * Set the value of Mail
- *
- *
- * @param mixed mail
- *
- */
- public function setMail($mail) {
- $this->mail = $mail;
- }
- /**
- * Get the value of Admin
- *
- *
- * @return mixed
- *
- */
- public function getAdmin() {
- return $this->admin;
- }
- /**
- * Set the value of Admin
- *
- *
- * @param mixed admin
- *
- */
- public function setAdmin($admin) {
- $this->admin = $admin;
- }
- }
|