Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static function isAuth():Bool {
- var c = neko.Web.getCookies();
- if (c.exists("hx_a") && c.exists("hx_u")) {
- var user = db.User.manager.get(Std.parseInt(c.get("hx_u")));
- if (user == null)
- return false;
- if (Auth.buildHash(user.name,user.password) == c.get("hx_a")) {
- var t = getCookieTime();
- neko.Web.setCookie("hx_u", Std.string(user.id), t, Config.config.cookie.domain, Config.config.cookie.path);
- neko.Web.setCookie("hx_a", buildHash(user.name,user.password), t, Config.config.cookie.domain, Config.config.cookie.path);
- return true;
- }
- }
- return false;
- }
- public static inline function getUser():db.User
- return db.User.manager.get(Std.parseInt(neko.Web.getCookies().get("hx_u")))
- private static inline function buildHash(name:String,password:String)
- return Md5.encode(Config.config.cookie.salt+name+Md5.encode(password))
- private static inline function getCookieTime()
- return Date.fromTime((Date.now().getTime())+60*1000*Config.config.cookie.time)
- public static function login(name:String,password:String) {
- var u = db.User.manager.search({name:name}).first();
- if (u.password == Md5.encode(password)) {
- var t = getCookieTime();
- neko.Web.setCookie("hx_u", Std.string(u.id), t, Config.config.cookie.domain, Config.config.cookie.path);
- neko.Web.setCookie("hx_a", buildHash(u.name,u.password), t, Config.config.cookie.domain, Config.config.cookie.path);
- return true;
- }
- return false;
- }
- public static function logout() {
- neko.Web.setCookie("hx_u","", Date.now(), Config.config.cookie.domain, Config.config.cookie.path);
- neko.Web.setCookie("hx_a","", Date.now(), Config.config.cookie.domain, Config.config.cookie.path);
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement