public ActionResult Validate(LoginModel obj) { obj.isadmin = true; var check = UserDal.ValidateUser(obj); if (check!=null) { FormsAuthentication.SetAuthCookie("admin", false); FormsAuthenticationTicket ticket = new FormsAuthenticationTicket( 1, // ticket version check.Email, // authenticated username DateTime.Now, // issueDate DateTime.Now.AddDays(2), // expiryDate false, // true to persist across browser sessions check.Name + "-" + check.id, // can be used to store additional user data FormsAuthentication.FormsCookiePath); string encryptedTicket = FormsAuthentication.Encrypt(ticket); HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); cookie.HttpOnly = true; Response.Cookies.Add(cookie); return RedirectToAction("Index", "Category"); } else { TempData["ErrorMessage"] = "Invalid Username and password"; return RedirectToAction("Index", "home"); } }
// // GET: /Admin/Base/ protected LoginModel GetLoginUserdata() { LoginModel obj = new LoginModel(); HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName]; if (authCookie != null) { FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value); string userData = ticket.UserData; obj.Name = userData.Split('-')[0]; obj.id = Convert.ToInt32(userData.Split('-')[1]); } return obj; }
public static adminUser ValidateUser(LoginModel loginobj) { adminUser User = null; var context = new Ecommerce.DbEntity.ecommerceEntities(); var obj = context.users.Where(m => m.Email == loginobj.Email && m.Password == loginobj.Password && m.Isadmin == loginobj.isadmin).FirstOrDefault(); if (obj != null) { User = new adminUser(); User.Address1 = obj.Address1; User.Address2 = obj.Address2; User.City = obj.City; User.ContactNumber = obj.ContactNumber; User.Country = obj.Country; User.DAddress1 = obj.DAddress1; User.DAddress2 = obj.DAddress2; User.DCity = obj.DCity; User.DCountry = obj.DCountry; User.DName = obj.DName; User.DPostCode = obj.DPostCode; User.DState = obj.DState; User.Email = obj.Email; User.Name = obj.Name; User.Password = obj.Password; User.PostCode = obj.PostCode; User.State = obj.State; } return User; }
public static bool RegisterUser(LoginModel loginobj) { bool check = true; try { var context = new Ecommerce.DbEntity.ecommerceEntities(); context.users.Add(new DbEntity.user { Name=loginobj.FirstName+" "+loginobj.LastName, Password = loginobj.Password, Email = loginobj.RegistrationEmail, Address1 = "", Address2 ="", City = "", ContactNumber = "", Country = "", DAddress1 = "", DAddress2 = "", DCity ="", DCountry = "", DName = "", DPostCode = "", DState = "", PostCode = "", State = "", Isadmin=false }); if (loginobj.SubscribeForNewLetter) { context.newletters.Add(new DbEntity.newletter { email = loginobj.RegistrationEmail }); } context.SaveChanges(); } catch (Exception ex) { check = false; } return check; }
public JsonResult RegisterUser(LoginModel obj) { bool check=false; check = UserDal.RegisterUser(obj); return Json("You have successfully registered"); }
public JsonResult SendEmailForgotPassword(LoginModel obj) { var OutputMessage = ""; var user = UserDal.GetByemail(obj.EmailForgotPassword); if (user.Name != null) { Utility.SendEmail(user.Email, "Message", "Password Recovery " + ConfigurationManager.AppSettings["WebsiteName"].ToString(), user.Name); OutputMessage = "Password is send at your email address."; } else { OutputMessage = "This email address is not registerd."; } return Json(OutputMessage); }