public void ResendActivationEmail(string email, IMailer mailer) { EnsureLoggedOff(); var targetEmail = Validator.ValidateEmail(email).ToLower(); var loginUser = _userOperations.GetLoginUser(targetEmail); var user = _userOperations.Get(loginUser.UserId); if (user.Activated) { throw new ActivationException("User already activated"); } mailer.SendActivationMail(user.Id, user.Name, user.Email, user.ActivationCode, _settingProvider.ManagementApiUrl); }
public string Register(RegisterDto register, IMailer mailer) { register.Email = Validator.ValidateEmail(register.Email); register.Name = Validator.TrimAndValidateAsName(register.Name); Validator.ValidatePassword(register.Password); var user = Mapper.Map <RegisterDto, User>(register); user.Email = user.Email.ToLower(); if (_userOperations.IsExists(user.Email)) { throw new AlreadyExistsException(); } var needsActivation = _settingProvider.EmailActivation; if (!needsActivation) { user.Activated = true; } else { user.Activated = false; user.ActivationCode = Identity.Next(); } var salt = Crypto.GenerateSalt(); var passwordHash = Crypto.CalcualteHash(register.Password, salt); var userId = _userOperations.Create(user, passwordHash, salt); if (needsActivation) { mailer.SendActivationMail(userId, user.Name, user.Email, user.ActivationCode, _settingProvider.WebsiteUrl); } else { _authenticationContext.SetContextUser(userId); EnsureEnvironment(); } return(userId); }