public virtual async Task <AccountResult <string> > RegisterAsync(Models.RegisterInfo register)
        {
            if (register.Password != register.ConfirmPassword)
            {
                return(AccountResult.Unsuccessful(data: "", "两次密码不一致"));
            }

            var user = await GetUserFromEmailAsync(register.Email);

            if (user != null)
            {
                return(AccountResult.Unsuccessful(data: "", "已经被使用的邮箱"));
            }

            user = new ScreamBackend.DB.Tables.User
            {
                Email           = register.Email,
                NormalizedEmail = Formator.EmailNormaliz(register.Email),
                Username        = Formator.SplitUsernameFromEmail(register.Email),
                PasswordHash    = register.Password
            };
            user.NormalizedUsername = Formator.UsernameNormaliz(user.Username);

            _db.Users.Add(user);
            int effects = await _db.SaveChangesAsync();

            if (effects == 1)
            {
                return(AccountResult.Successful(user.Email));
            }
            throw new Exception("Register fail");
        }
示例#2
0
        public static AccountResult <T> Unsuccessful <T>(T data, params string[] errors)
        {
            var baseResult = Unsuccessful(errors);

            return(AccountResult <T> .Parse(baseResult, data, baseResult.Errors));
        }
示例#3
0
        public static AccountResult <T> Successful <T>(T data)
        {
            var result = Successful();

            return(AccountResult <T> .Parse(result, data, new List <string>()));
        }