Ejemplo n.º 1
0
        public ActionResult Update(UsersModel users)
        {
            ResponseData responseData = new ResponseData();

            WIS.Entities.Account usersModel = _accountBo.GetById(users.UserId);
            if (usersModel != null && usersModel.Id > 0)
            {
                bool isSendMail = !usersModel.Email.Equals(users.Email);
                usersModel.FullName = users.FullName;
                usersModel.Email    = users.Email;
                usersModel.Birthday = users.Birthday;
                usersModel.Avatar   = users.Avatar;
                usersModel.Address  = users.Address;
                usersModel.Gender   = users.Gender;
                usersModel.Phone    = users.Mobile;
                usersModel.UserType = users.UserType.Value;

                ErrorCodes errorCode = _accountBo.Update(usersModel);

                Msg.Error = errorCode != ErrorCodes.Success;
                Msg.Title = StringUtils.GetEnumDescription(errorCode);
                return(AuthorizeJson(Msg));
            }

            WIS.Entities.Account usersByName = _accountBo.GetByUserName(users.UserName);
            if (usersByName == null || usersByName.Id <= 0)
            {
                string strPass = Guid.NewGuid().ToString().Replace("-", "").Substring(0, 6);
                WIS.Entities.Account usersModelTemp = new Account();
                usersModelTemp.UserName         = users.UserName;
                usersModelTemp.Password         = Crypton.Encrypt(strPass);
                usersModelTemp.FullName         = users.FullName;
                usersModelTemp.Email            = users.Email;
                usersModelTemp.Birthday         = users.Birthday;
                usersModelTemp.Avatar           = users.Avatar;
                usersModelTemp.Address          = users.Address;
                usersModelTemp.PasswordQuestion = string.Empty;
                usersModelTemp.PasswordAnswer   = string.Empty;
                usersModelTemp.CreatedDate      = DateTime.Now;
                usersModelTemp.Status           = (int)UserStatusAdmin.Actived;
                usersModelTemp.Gender           = users.Gender;
                usersModelTemp.Phone            = users.Mobile;
                usersModelTemp.UserType         = users.UserType.Value;

                ErrorCodes errorCodes = _accountBo.Insert(usersModelTemp);
                Msg.Error = errorCodes != ErrorCodes.Success;
                Msg.Title = StringUtils.GetEnumDescription(errorCodes);
                return(AuthorizeJson(Msg));
            }

            Msg.Error = true;
            Msg.Title = StringUtils.GetEnumDescription(ErrorCodes.UserNameExisted);
            return(AuthorizeJson(Msg));
        }
Ejemplo n.º 2
0
        public void DoLogin(string accountName, ref ResponseData loginResult, bool saveCookie)
        {
            if (!IsLogin())
            {
                try
                {
                    bool             @bool    = AppSettings.Instance.GetBool(Const.DebugMode);
                    Entities.Account userInfo = _accountBo.GetByUserName(accountName);
                    if ((userInfo != null) && (userInfo.Id > 0))
                    {
                        UserLogin login = new UserLogin(userInfo);

                        //var claims = new List<Claim>
                        //{
                        //    new Claim(ClaimTypes.Name, login.UserName),
                        //    new Claim(ClaimTypes.Role, login.UserType.ToString())
                        //};

                        //var userIdentity = new ClaimsIdentity(claims, "login");

                        //ClaimsPrincipal principal = new ClaimsPrincipal(userIdentity);
                        //AuthenticationHttpContextExtensions.SignInAsync(_httpContextAccessor.HttpContext, CookieAuthenticationDefaults.AuthenticationScheme, principal);

                        string token = string.Empty;
                        // lưu checksumKey và token vào cache
                        loginResult.Success = this.JwtLogin(login, out token);
                        //return the token
                        loginResult.Token     = token;
                        loginResult.Success   = true;
                        loginResult.Message   = StringUtils.GetEnumDescription(ErrorCodes.Success);
                        loginResult.ErrorCode = (int)ErrorCodes.Success;

                        // Lưu cache nếu user là Cashier
                        if (login.UserType == UserTypeEnum.Cashier.GetHashCode())
                        {
                            SetOnlyCashier(login.UserName);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.WriteLog(Logger.LogType.Error, ex.ToString());
                }
            }
        }