/** * Save properties of the user profile * @return [JSON] Success or error message */ public static function saveProfile() { if (!Flight::has('currentUser')) { Flight::json(['Error' => 'No Access']); } $currentUser = Flight::get('currentUser'); if (isset(Flight::request()->query->bio)) { $currentUser->bio = Flight::request()->data->bio; } else { if (isset(Flight::request()->query->password)) { if (!isset(Flight::request()->data->passwordold) || !isset(Flight::request()->data->passwordnew1) || !isset(Flight::request()->data->passwordnew2)) { Flight::json(['success' => false, 'exception' => 'Empty fields']); } if ($currentUser->password === hash("sha256", Flight::request()->data->passwordold)) { if (Flight::request()->data->passwordnew1 == Flight::request()->data->passwordnew2) { $currentUser->password = hash("sha256", Flight::request()->data->passwordnew1); } else { Flight::json(['success' => false, 'exception' => 'New passwords are not the same']); } } else { Flight::json(['success' => false, 'exception' => 'Old password is not correct ']); } } } $result = $currentUser->update(); if ($result != false) { $_SESSION['user'] = Flight::users()->getUserWithId(Flight::get('currentUser')->id); Flight::json(['success' => true]); } else { Flight::json(['sucess' => false, 'exception' => 'An error']); } }
public function showUserSettings($id) { if ($id == null) { Flight::auth()->check(); $user = Flight::auth()->currentUser; } else { Flight::auth()->check(20); $user = Flight::users()->getUserWithId($id); } Flight::util()->render('editUser', array("teams" => Flight::teams()->getAllTeams(), "user" => $user)); }
public static function author($id = null) { if ($id == null) { if (Flight::has('currentUser')) { $user = Flight::get('currentUser'); } else { Flight::redirect("/"); } } else { $user = Flight::users()->getUserWithId($id); } Flight::util()->render('profile', ['user' => $user]); }
/** * Login with email and password */ public static function login() { $email = Flight::request()->data->email; $password = Flight::request()->data->password; $user = Flight::users()->getUserWithEmail($email); if ($user == false) { Flight::util()->render('login', ['error' => 'login']); } else { if (hash("sha256", $password) == $user->password) { $_SESSION['user'] = $user; Flight::redirect("/"); } else { Flight::util()->render('login', ['error' => 'login']); } } }