public JsonResult CheckConnection(AuthObj obj) { try { getConnection(); } catch (Exception) { return(Json(new { danger = "Connection to database fail, Please try again!" })); } return(Json(new { success = "Đăng nhập thành công!" })); }
public JsonResult Login(AuthObj obj) { try { var Con = new TM.Core.Connection.Oracle("ORA_PORTAL"); var qry = ""; //var collection = HttpContext.Request.ReadFormAsync(); //string username = collection["username"].ToString(); //string password = collection["password"].ToString(); //AuthStatic var AuthStatic = Authentication.Core.Auth.isAuthStatic(obj.username, obj.password); if (AuthStatic != null) { Authentication.Core.Auth.SetAuth(AuthStatic); return(Json(new { success = "Đăng nhập thành công!", url = TM.Core.Helper.Url.RedirectContinue() })); } //AuthDB qry = $"SELECT * FROM users WHERE username='******'"; var user = Con.Connection.QueryFirstOrDefault <Authentication.Core.Users>(qry); // db.users.SingleOrDefault(u => u.username == username); //Account not Exist if (user == null) { return(Json(new { danger = "Sai tên tài khoản hoặc mật khẩu!" })); } //Password wrong obj.password = TM.Core.Encrypt.MD5.CryptoMD5TM(obj.password + user.salt); if (user.password != obj.password) { return(Json(new { danger = "Sai tên tài khoản hoặc mật khẩu!" })); } //Account is locked if (user.flag < 1) { return(Json(new { danger = "Tài khoản đã bị khóa. Vui lòng liên hệ admin!" })); } //Update last login user.lastlogin = DateTime.Now; Con.Connection.Update(user); //Set Auth Account Authentication.Core.Auth.SetAuth(user, AuthRoles(user), AuthAllowRoles()); var b = Authentication.Core.Auth.AuthUser; var c = Authentication.Core.Auth.isAuth; //return Redirect(TM.Url.RedirectContinue()); } catch (Exception) { return(Json(new { danger = "Đăng nhập không thành công, vui lòng liên hệ admin!" })); } return(Json(new { success = "Đăng nhập thành công!", url = TM.Core.Helper.Url.RedirectContinue(obj.currentUrl, true) })); }