示例#1
0
        public static bool Create(RegisterModel data)
        {
            if (_userMethods.UserExists(data.Username))
            {
                return(false);
            }

            if (_userMethods.EmailExists(data.Email))
            {
                return(false);
            }

            var newUser = new User {
                Username    = data.Username,
                DisplayName = data.Username,
                Email       = data.Email,
                Salt        = UserValidation.GenerateSalt(),
                HasGravatar = false,
                ProfilePic  = ""
            };

            newUser.Password = UserValidation.HashText(data.Password, newUser.Salt, new SHA512CryptoServiceProvider());

            _userMethods.CreateUser(newUser);

            if (!_userMethods.UserExists(newUser.Username))
            {
                return(false);
            }

            var user = _userMethods.GetUserByUsername(newUser.Username);

            var verification = UserValidation.GenerateSalt();

            _userMethods.AddVerification(user.Id, verification);

            Email.Send("Registration", data.Email, "Verification", new Dictionary <string, string> {
                { "username", data.Username }, { "verification", verification }, { "url", Settings.Url }
            }, _emailTemplateMethods);

            return(true);
        }