public async Task <IActionResult> Index() { Mcustomer user = new Mcustomer(); string cookieValue = Request.Cookies["ChatUser"]; if (cookieValue != null) { UserModal obj = JsonConvert.DeserializeObject <UserModal>(cookieValue); user = await new UserHandler().Authenticate(obj.CustomerCode, obj.Password); } return(View(user)); }
public async Task OfflineUser(Guid id) { using (Context db = new Context()) { try { Mcustomer cust = db.Mcustomers.Where(s => s.Id == id).FirstOrDefault(); if (cust != null) { cust.Online = false; db.Mcustomers.Update(cust); db.SaveChanges(); } } catch (Exception ex) { string error = ex.ToString(); throw; } } }
public async Task <IActionResult> LogIn(string email, string Password, bool RememberMe) { string result = string.Empty; try { Mcustomer user = await new UserHandler().Authenticate(email, Password); if (user != null) { UserModal model = new UserModal(); model.Id = user.Id; model.CustomerCode = user.CustomerCode; model.FirstName = user.FirstName; model.LastName = user.LastName; model.Password = user.Password; model.Role = 1; HttpContext.Session.SetObject(WebUtil.User, model); //new code if (RememberMe == true) { CookieOptions option = new CookieOptions(); option.Expires = DateTime.Now.AddDays(3); string value = JsonConvert.SerializeObject(user); Response.Cookies.Append("ChatUser", value, option); } } else { result = "Invalid Email or Password"; } } catch (Exception ex) { result = ex.Message; Response.StatusCode = 404; } return(Json(result)); }
public async Task <Mcustomer> Authenticate(string email, string password) { using (Context db = new Context()) { try { Mcustomer user = (from m in db.Mcustomers where m.CustomerCode == email && m.Password == password select m).FirstOrDefault(); if (user != null) { user.Online = true; db.Mcustomers.Update(user); db.SaveChanges(); } return(user); } catch (Exception ex) { string error = ex.ToString(); throw; } } }