Esempio n. 1
0
        public static bool Register(ResultModel result, RegisterModel Model)
        {
            #region 表单验证
            ValidationContext       context = new ValidationContext(Model, null, null); ///创建验证实体
            List <ValidationResult> results = new List <ValidationResult>();            ///返回的ErrorMsgList
            var valid = Validator.TryValidateObject(Model, context, results, true);     ///执行验证
            if (!valid)
            {
                result.ErrorCode = -1;
                result.ErrorMsg  = $"注册失败 {results.FirstOrDefault()?.ErrorMessage}";
                return(false);
            }
            if (ValidateCodeHelper.CurrentCodeString != Model.VerisonCode.ToLower())
            {
                result.ErrorCode = -1;
                result.ErrorMsg  = $"注册失败 验证码错误";
                return(false);
            }
            #endregion

            ValidateCodeHelper.DeleteCodeString();//清除验证码

            #region 注册方法
            var UserOID   = Guid.NewGuid().ToString();
            var UserModel = new Data_User()
            {
                OID        = UserOID,
                Name       = Model.UserName,
                UserName   = Model.UserName,
                Password   = EncryptionHelper.HMACSMD5Encrypt(Model.Password, UserOID, Encoding.ASCII),
                Telephone  = Model.Telephone,
                IsDeleted  = false,
                IsLocked   = false,
                CreateTime = DateTime.Now
            };
            return(UserModel.Add());

            #endregion
        }