Beispiel #1
0
        public async Task<long> RegisterUser(string email, string password, string lastName, 
            string firstName, string middleName, AuthType? authType, string authId, bool confirmEmail)
        {
            var salt = password == null? null: PasswordHash.CreateSalt();
            var passwordHash = password == null ? null : PasswordHash.CreateHash(salt, password);

            var user = new User
            {
                AuthID = authId,
                AuthType = authType,
                Confirmed = authType.HasValue && !confirmEmail,
                DateJoined = DateTime.UtcNow,
                Deleted = false,
                Email = email,
                FirstName = firstName,
                LastName = lastName,
                MiddleName = middleName,
                Password = passwordHash,
                Salt = salt,
                Role = Role.Voter
            };

            user.Id = await userRepository.Add(user);

            if (!authType.HasValue || confirmEmail)
            {
                await SendConfirmationEmail(user);
            }
            return user.Id;
        }
Beispiel #2
0
 public Task<int> UpdateUser(User user)
 {
     return userRepository.Update(user);
 }
Beispiel #3
0
        public async Task SendConfirmationEmail(User user)
        {
            user.ConfirmationToken = PasswordHash.CreateSalt();
            await userRepository.Update(user);

            var mailModel = new AccountConfirmation("Account Confirmation", user.Email,
                ConfigurationManager.AppSettings["WebsiteUrl"] + "#/confirm?token=" + HttpUtility.UrlEncode(user.ConfirmationToken));

            await emailSender.Send(mailModel);
        }