daily pastebin goal
5%
SHARE
TWEET

Untitled

a guest May 30th, 2017 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static function isAuth():Bool {
  2.         var c = neko.Web.getCookies();
  3.         if (c.exists("hx_a") && c.exists("hx_u")) {
  4.             var user = db.User.manager.get(Std.parseInt(c.get("hx_u")));
  5.             if (user == null)
  6.                 return false;
  7.             if (Auth.buildHash(user.name,user.password) == c.get("hx_a")) {
  8.                 var t = getCookieTime();
  9.                 neko.Web.setCookie("hx_u", Std.string(user.id), t, Config.config.cookie.domain, Config.config.cookie.path);
  10.                 neko.Web.setCookie("hx_a", buildHash(user.name,user.password), t, Config.config.cookie.domain, Config.config.cookie.path);
  11.                 return true;               
  12.             }
  13.         }
  14.         return false;  
  15.     }
  16.    
  17.     public static inline function getUser():db.User
  18.         return db.User.manager.get(Std.parseInt(neko.Web.getCookies().get("hx_u")))
  19.    
  20.     private static inline function buildHash(name:String,password:String)
  21.         return Md5.encode(Config.config.cookie.salt+name+Md5.encode(password))
  22.  
  23. private static inline function getCookieTime()
  24.         return Date.fromTime((Date.now().getTime())+60*1000*Config.config.cookie.time)
  25.    
  26.     public static function login(name:String,password:String) {
  27.         var u = db.User.manager.search({name:name}).first();
  28.         if (u.password == Md5.encode(password)) {
  29.             var t = getCookieTime();
  30.             neko.Web.setCookie("hx_u", Std.string(u.id), t, Config.config.cookie.domain, Config.config.cookie.path);
  31.             neko.Web.setCookie("hx_a", buildHash(u.name,u.password), t, Config.config.cookie.domain, Config.config.cookie.path);
  32.             return true;       
  33.         }      
  34.         return false;
  35.     }
  36.    
  37.     public static function logout() {
  38.         neko.Web.setCookie("hx_u","", Date.now(), Config.config.cookie.domain, Config.config.cookie.path);
  39.         neko.Web.setCookie("hx_a","", Date.now(), Config.config.cookie.domain, Config.config.cookie.path);
  40.         return true;
  41.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top