コード例 #1
0
        public JsonResult Login(FormCollection collection)
        {
            var userModel = this.AccountService.FindByUsername(collection.Get("username"));

            if (userModel != null && !string.IsNullOrEmpty(userModel.Password) &&
                EncryptionUtility.BcryptCheckPassword(collection.Get("password"), userModel.Password))
            {
                if (userModel.Status.Value)
                {
                    SessionUtility.SetAuthenticationToken(userModel, 60);

                    return(new JsonResult {
                        ContentType = "text", Data = new { msg = "success" }
                    });
                }
                else
                {
                    return new JsonResult {
                               ContentType = "text", Data = new { msg = Constant.CONST_MESSAGE_LOGIN_DISABLE }
                    }
                };
            }

            return(new JsonResult {
                ContentType = "text", Data = new { msg = Constant.CONST_MESSAGE_LOGIN_INVALID }
            });
        }
コード例 #2
0
        public ActionResult Login(FormCollection collection)
        {
            var userModel = this.AccountService.FindByUsername(collection.Get("username"));

            if (userModel != null && !string.IsNullOrEmpty(userModel.Password) &&
                EncryptionUtility.BcryptCheckPassword(collection.Get("password"), userModel.Password))
            {
                if (userModel.Status.Value)
                {
                    var callBackUrl = collection.Get("callUrl");

                    SessionUtility.SetAuthenticationToken(userModel, 60);

                    if (!string.IsNullOrEmpty(callBackUrl))
                    {
                        return(RedirectToAction(callBackUrl.Split('/')[1], callBackUrl.Split('/')[0]));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    return(RedirectToAction("Login", new { msg = Constant.CONST_MESSAGE_LOGIN_DISABLE }));
                }
            }

            return(RedirectToAction("Login", new { msg = Constant.CONST_MESSAGE_LOGIN_INVALID }));
        }
コード例 #3
0
        public JsonResult ChangePassword(FormCollection collection)
        {
            var result = new JsonResult {
                ContentType = "text"
            };
            var loggedUser = this.AccountService.Find(SessionUtility.GetLoggedUser().ID);

            if (EncryptionUtility.BcryptCheckPassword(collection.Get("CurrentPassword"), loggedUser.Password))
            {
                loggedUser.Password = EncryptionUtility.BcryptHashPassword(collection.Get("NewPassword"));
                this.AccountService.Update(loggedUser);
                SessionUtility.SetAuthenticationToken(loggedUser, 60);

                result.Data = new { type = "success" };
            }
            else
            {
                result.Data = new { type = "error" }
            };

            return(result);
        }