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: " . $GLOBALS['conf']['baseURL']); } else { echo "PW mismatch, try again."; exit(1); } } public static function logout() { session_destroy(); header("Location: " . $GLOBALS['conf']['baseURL']); } 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; } }