Exemple #1
0
        /// <summary>
        /// 验证用户密码
        /// </summary>
        /// <param name="account"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public AccountUserLoginResults ValidateAccountUser(string account, string password)
        {
            var customer = _customerService.GetAccountUserByAccount(account);

            if (customer == null)
            {
                return(AccountUserLoginResults.AccountUserNotExist);
            }
            if (customer.Deleted)
            {
                return(AccountUserLoginResults.Deleted);
            }
            if (!customer.Active)
            {
                return(AccountUserLoginResults.NotActive);
            }
            //only registered can login
            if (!customer.IsRegistered())
            {
                return(AccountUserLoginResults.NotRegistered);
            }

            string pwd = "";

            switch (customer.PasswordFormat)
            {
            case PasswordFormat.Encrypted:
                pwd = _encryptionService.EncryptText(password);
                break;

            case PasswordFormat.Hashed:
                pwd = _encryptionService.CreatePasswordHash(password, customer.PasswordSalt, _customerSettings.HashedPasswordFormat);
                break;

            default:
                pwd = password;
                break;
            }

            bool isValid = pwd == customer.Password;

            if (!isValid)
            {
                return(AccountUserLoginResults.WrongPassword);
            }

            //save last login date
            customer.LastLoginDate = DateTime.Now;
            _customerService.UpdateAccountUser(customer);
            return(AccountUserLoginResults.Successful);
        }
Exemple #2
0
        public IHttpActionResult ResetPWD()
        {
            var users = _accountUserService.GetAllAccountUsers();

            foreach (var user in users)
            {
                user.PasswordFormat = PasswordFormat.Encrypted;
                user.Password       = _encryptionService.EncryptText(user.Password);

                _accountUserService.UpdateAccountUser(user);
            }

            return(Ok());
        }
        /// <summary>
        /// 验证用户的正确性
        /// </summary>
        /// <param name="account"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public Task <AccountUser> ValidateAccountUserAsync(string account, string password)
        {
            if (string.IsNullOrWhiteSpace(password))
            {
                throw new ArgumentNullException("密码不能为空");
            }

            var accountUser = _accountUserService.GetAccountUserByUsername(account);

            if (accountUser != null)
            {
                bool passwordCorrect = false;
                switch (accountUser.PasswordFormat)
                {
                case PasswordFormat.Clear:
                {
                    passwordCorrect = password == accountUser.Password;
                }
                break;

                case PasswordFormat.Encrypted:
                {
                    passwordCorrect = _encryptionService.EncryptText(password) == accountUser.Password;
                }
                break;

                case PasswordFormat.Hashed:
                {
                    string saltKey = _encryptionService.CreateSaltKey(5);
                    passwordCorrect = _encryptionService.CreatePasswordHash(password, saltKey, _customerSettings.HashedPasswordFormat) == accountUser.Password;
                }
                break;

                default:
                    break;
                }

                if (passwordCorrect)
                {
                    accountUser.LastLoginDate = DateTime.Now;

                    _accountUserService.UpdateAccountUser(accountUser);

                    return(Task.FromResult(accountUser));
                }
            }

            return(Task.FromResult <AccountUser>(null));;
        }
Exemple #4
0
        public IHttpActionResult UpdateAccount(int accountId, AccountUserModel accountModel)
        {
            var account = _accountService.GetAccountUserById(accountId);

            if (account == null || account.Deleted)
            {
                return(NotFound());
            }
            account = accountModel.ToEntity(account);

            var registerRole = _accountService.GetAccountUserRoleBySystemName(SystemAccountUserRoleNames.Registered);

            account.AccountUserRoles.Clear();

            var role = _accountService.GetAccountUserRoleBySystemName(accountModel.RoleName);

            if (role != null && accountModel.RoleName != SystemAccountUserRoleNames.Registered)
            {
                account.AccountUserRoles.Add(role);
            }
            account.AccountUserRoles.Add(registerRole);

            if (accountModel.InitPassword)
            {
                account.Password = "******";                             //设置初始密码
            }
            //单位更新
            if (accountModel.GovernmentId != account.Government.Id)
            {
                var governament = _governmentService.GetGovernmentUnitById(accountModel.GovernmentId);
                if (governament == null)
                {
                    return(BadRequest("用户所属单位不存在"));
                }
                account.Government = governament;
            }

            //保存用户
            _accountService.UpdateAccountUser(account);

            //activity log
            _accountUserActivityService.InsertActivity("UpdateAccount", "更新 名为 {0} 的用户的基本信息", account.UserName);

            //SuccessNotification(_localizationService.GetResource("Admin.Catalog.Categories.Added"));

            return(Ok(account.ToModel()));
        }
Exemple #5
0
        public IHttpActionResult LoggingUser(string authCode = "")
        {
            if (string.IsNullOrEmpty(authCode))
            {
                return(BadRequest("AuthCode is invalid"));
            }

            var dingdingUserInfo = _ddTalkService.GetUserInfo(authCode);

            if (dingdingUserInfo.IsError)
            {
                return(BadRequest("Get UserInfo Error ,because " + dingdingUserInfo.ErrMsg));
            }

            var account = _accountUserService.GetAccountUserByDDUserId(dingdingUserInfo.Userid);

            if (account != null)
            {
                account.LastActivityDate = DateTime.Now;
                account.LastLoginDate    = DateTime.Now;
                account.LastIpAddress    = _webHelper.GetCurrentIpAddress();
                account.FirstTime        = false;
                _accountUserService.UpdateAccountUser(account);
            }
            else
            {
                account = new AccountUser
                {
                    FirstTime        = true,
                    Active           = true,
                    DDUserId         = dingdingUserInfo.Userid,
                    NickName         = dingdingUserInfo.Name,
                    LastActivityDate = DateTime.Now,
                    LastLoginDate    = DateTime.Now,
                    LastIpAddress    = _webHelper.GetCurrentIpAddress(),
                };
                _accountUserService.InsertAccountUser(account);
            }

            return(Ok("Guid:" + account.AccountUserGuid));
        }