public ActionResult PLogin(Web.ViewModels.User.pLoginVM model) { rs r; if (ModelState.IsValid) { try { SimpleAES __aes = new SimpleAES(); string __pw_aes = __aes.EncryptToString(model.Password); var _login = __db.Users.FirstOrDefault(f => f.Username == model.Username && f.Password == __pw_aes); if (_login != null) { DateTime exp = DateTime.UtcNow.AddYears(1); var token = EncodeDecodeJWT.Encode(new Dictionary <string, object> { { "uid", _login.Id }, { "exp", exp.toJWTString() } }); myCookies.Set("auth", token, exp); loginVM log = new loginVM(_login); MySsAuthUsers.setLogin(log); r = rs.T("Ok!"); } else { r = rs.F("Ok!"); } } catch (Exception ex) { r = rs.F(ex.Message); } } else { r = rs.F("Lỗi nhập liệu!"); } if (!r.r) { ModelState.AddModelError(string.Empty, r.m); } else { if (string.IsNullOrEmpty(model.ReturnUrl) == false) { return(Redirect(myBase64EncodeDecode.DecodeBase64(model.ReturnUrl))); } else { return(RedirectToAction("Profile", "User")); } } return(View(model)); }
public JsonResult mLoginProcess(Web.ViewModels.User.pLoginVM model) { rs r; if (ModelState.IsValid) { try { SimpleAES __aes = new SimpleAES(); string __pw_aes = __aes.EncryptToString(model.Password); var _login = __db.Users.FirstOrDefault(f => f.Username == model.Username && f.Password == __pw_aes); if (_login != null) { DateTime exp = DateTime.UtcNow.AddYears(1); var token = EncodeDecodeJWT.Encode(new Dictionary <string, object> { { "uid", _login.Id }, { "exp", exp.toJWTString() } }); myCookies.Set("auth", token, exp); loginVM log = new loginVM(_login); MySsAuthUsers.setLogin(log); r = rs.T("Ok!"); } else { r = rs.F("Ok!"); } } catch (Exception ex) { r = rs.F(ex.Message); } } else { r = rs.F("Lỗi nhập liệu!"); } return(Json(r, JsonRequestBehavior.DenyGet)); }
public ActionResult mLogin() { Web.ViewModels.User.pLoginVM model = new Web.ViewModels.User.pLoginVM(); model.ReturnUrl = string.Empty; return(View(model)); }
public ActionResult PLogin(string ReturnUrl = "") { Web.ViewModels.User.pLoginVM model = new Web.ViewModels.User.pLoginVM(); model.ReturnUrl = ReturnUrl; return(View(model)); }