Ejemplo n.º 1
0
        public ActionResult ALogin(string username, string password)
        {
            LoginViewModel account = new LoginViewModel()
            {
                UserName = username,
                Password = password,
                RememberMe = true

            };

            string message = "";
            if (ModelState.IsValid)
            {
                var evasMembership = new GCMPMembershipProvider();
                if (evasMembership.ValidateUser(account.UserName, account.Password))
                {

                    var evasRole = new GCMPRoleProvider();
                    if (evasRole.IsUserInRole(account.UserName, "Administrator"))
                    {
                        FormsAuthentication.SetAuthCookie(account.UserName, true);
                        // * redirect to Admin Dashboard
                        message = "Chúc mừng Admin đã đăng nhập thành công";
                        //return RedirectToAction("Index", "AdminDashboard");

                    }
                    if (evasRole.IsUserInRole(account.UserName, "Moderator"))
                    {
                        FormsAuthentication.SetAuthCookie(account.UserName, true);
                        // * redirect to Retailer Dashboard
                        // return RedirectToAction("Index", "CustomerService");
                    }
                    if (evasRole.IsUserInRole(account.UserName, "User"))
                    {
                        FormsAuthentication.SetAuthCookie(account.UserName, true);
                        // * redirect to Retailer Dashboard
                        // return RedirectToAction homepage

                        //MigrateShoppingCart(account.UserName);

                    }
                }
                else
                {
                    message = "Email đăng nhập hoặc mật khẩu không chính xác.";
                }
            }
            // * in case of, email and password aren't correct!!

            return Json(message);
        }
Ejemplo n.º 2
0
        public ActionResult Authentication(LoginViewModel account, string returnUrl)
        {
            string messageReturn = "";
            if (ModelState.IsValid)
            {
                var gcmpMembership = new GCMPMembershipProvider();

                if (gcmpMembership.ValidateUser(account.UserName, account.Password))
                {

                    FormsAuthentication.SetAuthCookie(account.UserName, account.RememberMe);
                    var aa = User.Identity.Name;
                    return RedirectToAction("Index", "Home");
                }
            }
            else if (!account.UserName.IsNullOrWhiteSpace() && !account.Password.IsNullOrWhiteSpace())
            {
                AccountRegisterViewModel regmodel = new AccountRegisterViewModel
                {
                    Username = account.UserName,
                    Password = account.Password
                };

                var rs = _model.RegisterAccount(regmodel);
                if (rs)
                {

                    return RedirectToAction("RegisterSuccess", "Account", new { returnUrl = returnUrl, username = account.UserName, password = account.Password, remember = account.RememberMe });
                }
                else
                {
                    messageReturn = "Có lỗi trong quá trình đăng ký, xin vui lòng thử lại!";
                    return RedirectToAction("Authenfailed", "Account", new { returnUrl = returnUrl, message = messageReturn });
                }
            }
            // * in case of, email and password aren't correct!!
            messageReturn = "Sai email đăng nhập hoặc mật khẩu! Xin vui lòng thử lại!";

            return RedirectToAction("Authenfailed", "Account", new { returnUrl = returnUrl, message = messageReturn});
        }