-
-
- final class UserLogin {
- public function __construct() {
- }
공개 정적 함수 getUserInfo() {
- if (isset($_COOKIE["user_id"])&&$_COOKIE["user_id"]&&(trim($_COOKIE["user_id"])!="")) {
- if (isset($_SESSION["USER_INFO"]))
- return $_SESSION["USER_INFO"];
- $dao = new UserDao();
- $user = $dao->find ($_COOKIE["user_id"]);
- if ($user) {
- $_SESSION["USER_INFO"] = $user;
- setcookie("docloud_sid", session_id(), time() 36000 );
- setcookie("user_id", $_COOKIE["user_id"], time() 36000);
-
- if (array_key_exists("selected_prj_id", $_COOKIE))
- setcookie("selected_prj_id ", $_COOKIE["selected_prj_id"], time() 36000);
-
- if (array_key_exists("selected_class_id", $_COOKIE))
- setcookie("selected_class_id", $_COOKIE["selected_class_id"] , time() 36000);
-
- if (array_key_exists("selected_image_id", $_COOKIE))
- setcookie("selected_image_id", $_COOKIE["selected_image_id"], time() 36000);
-
- if (array_key_exists("test_image_ids", $_COOKIE))
- setcookie("test_image_ids", $_COOKIE["test_image_ids"], time() 36000);
-
- if (array_key_exists(" upload_image_ids", $_COOKIE))
- setcookie("upload_image_ids", $_COOKIE["upload_image_ids"], time() 36000);
- return $user;
- }
- }
- self: :clearCookie();
- null 반환;
- }
공개 정적 함수 setUserInfo($userInfo) {
- $_SESSION["USER_INFO"] = $userInfo;
- setcookie("docloud_sid", session_id(), time() 36000);
- setcookie("user_id" , $userInfo->getId(), time() 36000);
- }
public static function isLogin() {
- if (self::getUserInfo()) {
- return true;
- }
- return false;
- }
- < p> 공개 정적 함수 delUserInfo() {
- self::clearCookie();
- session_destroy();
- }
-
- 비공개 정적 함수clearCookie() {
- setcookie("docloud_sid", "", time() - 36000);
- setcookie("user_id", "", time() - 36000);
- setcookie("selected_prj_id", "", time() - 36000);
- setcookie("selected_class_id", "", time() - 36000);
- setcookie("selected_image_id", "", time() - 36000);
- setcookie("test_image_ids", "", time( ) - 36000);
- setcookie("upload_image_ids", "", time() - 36000);
- }
- }
- ?>
-
제제대码
2. 사용자가 관련 결정을 내리기 위해 사용자 이름과 비밀번호를 입력하면 전화하세요.
-
-
- require_once 'Init.php';
- if (UserLogin::isLogin() && $_COOKIE["user_id"]==1) {
- UserLogin::delUserInfo();
- }
- else if (UserLogin::isLogin()){
- Utils::redirect('welcome');
- }
$username = null;
- $password = null;
$msg = "";
if (isset($_POST['username']) && isset($_POST[ 'password'])) {
- $username = addlashes(trim(stripslashes($_POST ['username'])));
- $password = addlashes(trim(stripslashes($_POST ['password']) ));
- // 유효성 검사
- $errors = LoginValidator::validate($username, $password);
-
- if (empty($errors)) {
- // 저장
- $dao = new UserDao();
- $user = $dao->findByName($username);
- $last_login_ip = Utils::getIpAddress();
- $user->setLastLoginIp($ last_login_ip);
- $now = new DateTime();
- $user->setLastLoginTime($now);
- $dao->save($user);
- UserLogin::setUserInfo( $user);
- Flash::addFlash('로그인에 성공했습니다! ');
- Utils::redirect('welcome');
- }
-
- foreach ($errors as $e) {
- $msg .= $e->getMessage() ."
";
- }
- }
- ?>
-
코드 복사
|