/** * Create a new CSRF token. * Add token to session variable. * * @return string */ public static function createToken() { $token = md5(uniqid(rand(), true)); $sessionData = ['csrf_token' => $token]; Session::put($sessionData); return $token; }
/** * Get weather data from the session cache. * * @param $remote * @return mixed */ protected static function getData($remote) { if (!Session::has('weather-data')) { $weatherData = $remote->getData('http://api.openweathermap.org/data/2.5/weather?zip=' . ZIP_CODE . ',us', null); $sessionData = ['weather-data' => $weatherData]; Session::put($sessionData); return $weatherData; } return Session::get('weather-data'); }
/** * Authenticate a user. * * @return bool */ public function login(array $credentials) { try { $user = $this->_user->getUserByEmail($credentials['email']); } catch (Exception $e) { return false; } if (!$user) { return false; } $authenticated = password_verify($credentials['password'], $user->password); if (!$authenticated) { return false; } //Log the user into the application. $userSessionData = ['id' => $user->uid, 'user_email' => $user->email, 'user_name' => $user->name, 'logged_in' => true]; Session::put($userSessionData); return header('Location: ' . POST_LOGIN_URL); }