Exemple #1
0
        //[AllowAnonymous]
        //[ValidateAntiForgeryToken]
        public async Task <ActionResult> Login(Model_muser model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            //var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
            //switch (result)
            //{
            //    case SignInStatus.Success:
            //        return RedirectToLocal(returnUrl);
            //    case SignInStatus.LockedOut:
            //        return View("Lockout");
            //    case SignInStatus.RequiresVerification:
            //        return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
            //    case SignInStatus.Failure:
            //    default:
            //        ModelState.AddModelError("", "Invalid login attempt.");
            //        return View(model);
            //}
            return(View("/Home/Index"));
        }
Exemple #2
0
        //[ValidateAntiForgeryToken()]
        public ActionResult Login(Model_muser user)
        {
            try
            {
                if (user.useremailid != null && user.password != null)
                {
                    var userExistOrNot = _db.Users.Single(d => d.useremailid == user.useremailid && d.password == user.password);

                    if (userExistOrNot != null)                                                                                    // check user exist
                    {
                        var roles = _db.roles.Where(r => r.roleid == userExistOrNot.ref_roleid).Select(r => r.rolename).ToArray(); // get all roles

                        Model_userResultData userdata = new Model_userResultData();                                                // required data after login
                        userdata.userid   = userExistOrNot.userid;
                        userdata.username = userExistOrNot.username;
                        userdata.name     = userExistOrNot.name;
                        userdata.roles    = roles;

                        string userData = JsonConvert.SerializeObject(userdata); // convert to json

                        FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(
                            1,
                            user.useremailid,
                            DateTime.Now,
                            DateTime.Now.AddMinutes(30),
                            false,                                                      //pass here true, if you want to implement remember me functionality
                            userData);                                                  // Authenticate data

                        string     encTicket = FormsAuthentication.Encrypt(authTicket); // encrypt
                        HttpCookie faCookie  = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);
                        Response.Cookies.Add(faCookie);                                 // Add to cookie

                        //System.Web.HttpContext.Current.Session["UserName"] = userExistOrNot.username;
                        return(RedirectToAction("Index", "Dashboard"));
                    }
                    else
                    {
                        return(View());
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
            }
            return(View());
        }
Exemple #3
0
 public ActionResult Index(Model_muser u) // User save method
 {
     try
     {
         if (Request.Form["Submit"] == "Create User")
         {
             if (u.userid == 0)
             {
                 //u.ref_designationid = 1;
                 //u.ref_organizationid = 1;
                 // u.userlandlineno = "1234567891";
                 u.modifiedby       = 1;
                 u.modifieddate     = DateTime.Now;
                 u.createdby        = 1;
                 u.createddate      = DateTime.Now;
                 u.active           = true;
                 _db.Entry(u).State = System.Data.Entity.EntityState.Added;
                 _db.SaveChanges();
                 if (u.userid > 0)
                 {
                     obj.usermessage = "Successfully Created User Details";
                 }
             }
         }
         else if (Request.Form["Update"] == "Update User")
         {
             u.modifiedby       = 1;
             u.modifieddate     = DateTime.Now;
             u.createdby        = 1;
             u.createddate      = DateTime.Now;
             u.active           = true;
             _db.Entry(u).State = System.Data.Entity.EntityState.Modified;
             _db.SaveChanges();
             if (u.userid > 0)
             {
                 obj.usermessage = "Successfully Updated User Details";
             }
         }
     }
     catch (Exception ex)
     {
         obj.usermessage = ex.Message;
         Console.Write(ex.Message);
     }
     return(View(obj));
 }