public ActionResult LogOn(LogOnModel model) { var date = DateTime.Now; //var lg = new Ultils(); var code = Ultils.CodeLogin(date); if (Request.Url != null) { Utility._d = Request.Url.Host; } var obj = _dnLoginApi.Login(code, model.UserName, model.Password, model.RememberMe, Utility._d); if (obj != null && obj.UserId != Guid.Empty) { //Gọi stored báo login thành công #region Cookie CodeLogin var expires = model.RememberMe ? date.AddDays(5) : date.AddMinutes(20); var codeCookie = HttpContext.Request.Cookies["CodeLogin"]; //if (codeCookie == null) //{ codeCookie = new HttpCookie("CodeLogin") { Value = code, Expires = expires }; Response.Cookies.Add(codeCookie); //} //else //{ // codeCookie.Value = code; // codeCookie.Expires = expires; // Response.Cookies.Add(codeCookie); //} return(Redirect("/")); #endregion } ModelState.AddModelError("", string.Format("{0}Tên người dùng hoặc mật khẩu được cung cấp là không chính xác.", "")); return(View(model)); }
public ActionResult Register(CustomerItem customer) { var objr = new CustomerAppItem { Status = 0 }; try { if (!string.IsNullOrEmpty(customer.Phone) && !string.IsNullOrEmpty(customer.Password)) { if (_da.CheckUserName(customer.Phone)) { return(Json(new BaseResponse <CustomerItem>() { Erros = true, Message = "Số điện thoại đã tồn tại", }, JsonRequestBehavior.AllowGet)); } var daten = DateTime.Now; var date = daten.TotalSeconds(); var saltKey = FDIUtils.CreateSaltKey(5); var sha1PasswordHash = FDIUtils.CreatePasswordHash(customer.Password, saltKey); //get agencyinfo var agencyDA = new AgencyDA(); var agency = agencyDA.GetItem(customer.PhoneAgency); var obj = new Base.Customer { FullName = customer.FullName, Phone = customer.Phone, PasswordSalt = saltKey, PassWord = sha1PasswordHash, UserName = customer.UserName, DateCreated = date, IsDelete = false, IsActive = true, Reward = 0, AgencyID = agency?.ID }; _da.Add(obj); _da.Save(); IAuthContainerModel model = new JWTContainerModel() { Claims = new Claim[] { new Claim(ClaimTypes.Name, obj.UserName), new Claim("ID", obj.ID.ToString()), } }; IAuthService authService = new JWTService(); var token = authService.GenerateToken(model); var result = new BaseResponse <CustomerItem>() { Erros = false, Data = new CustomerItem() { FullName = obj.FullName, Phone = obj.Phone, Token = token } }; return(Json(result, JsonRequestBehavior.AllowGet)); var datee = daten.AddDays(5).TotalSeconds(); //var lg = new Ultils(); var code = Ultils.CodeLogin(daten); var dNlogin = new DN_Login { CustomerID = obj.ID, DateCreated = date, DateEnd = datee, Code = code, IsOut = false }; _dl.Add(dNlogin); _dl.Save(); objr = new CustomerAppItem { ID = obj.ID, Status = 1, }; } } catch (Exception ex) { Log2File.LogExceptionToFile(ex); } return(Json(objr, JsonRequestBehavior.AllowGet)); }
/// <summary> /// /// </summary> /// <param name="key"></param> /// <param name="phone">UserName</param> /// <param name="mobile">SĐT3G</param> /// <param name="pass">Mật khẩu</param> /// <param name="address">Địa chỉ</param> /// <returns></returns> public ActionResult Addapp(string key, string phone, string mobile, string pass, string address, string name, int gid) { var objr = new CustomerAppItem { UserName = phone, Status = 0 }; try { if (key == Keyapi && !string.IsNullOrEmpty(phone) && !string.IsNullOrEmpty(pass)) { if (_da.CheckUserName(phone)) { return(Json(objr, JsonRequestBehavior.AllowGet)); } var daten = DateTime.Now; var date = daten.TotalSeconds(); var saltKey = FDIUtils.CreateSaltKey(5); var sha1PasswordHash = FDIUtils.CreatePasswordHash(pass, saltKey); var obj = new Base.Customer { Address = address, FullName = name, GroupID = gid, Phone = phone, PasswordSalt = saltKey, PassWord = sha1PasswordHash, UserName = phone, DateCreated = date, IsDelete = false, IsActive = true, Reward = 0, }; _da.Add(obj); _da.Save(); var datee = daten.AddDays(5).TotalSeconds(); //var lg = new Ultils(); var code = Ultils.CodeLogin(daten); var dNlogin = new DN_Login { CustomerID = obj.ID, DateCreated = date, DateEnd = datee, Code = code, IsOut = false }; _dl.Add(dNlogin); _dl.Save(); objr = new CustomerAppItem { ID = obj.ID, UserName = phone, Address = address, FullName = name, Phone = mobile, Reward = 0, GroupID = gid, Status = 1, }; } } catch (Exception ex) { Log2File.LogExceptionToFile(ex); } return(Json(objr, JsonRequestBehavior.AllowGet)); }