public IActionResult Register(RegisterAccountForm registration) { logger.Info("Developer Portal: Register - Posted"); try { if (ModelState.IsValid) { DeveloperAccountDTO account = auth.RegisterUser(registration); logger.Info("Developer Portal: Register - Posted - New User Created", account.ForLogging()); return(RedirectToAction("AccountHome")); } ViewBag.FormError = true; return(View()); } catch (Exception e) { logger.Error("Developer Portal: Regiester - Posted ERROR", e); if (e.GetType() == typeof(EmailAlreadyExistsError)) { ViewBag.EmailAlreadyExists = true; } else { ViewBag.DatabaseError = true; } return(View()); } }
public DeveloperAccountDTO RegisterUser(RegisterAccountForm registration) { DeveloperAccountDTO account; try { string encryptedPassword = passwordService.HashPassword(registration.Password); account = new DeveloperAccountDTO() { FirstName = registration.FirstName, LastName = registration.LastName, Email = registration.Email, AccountCreationDate = DateTime.Now, Password = encryptedPassword, Role = "Developer", Verified = true }; } catch { throw new PasswordEncryptionException(); } try { accountsService.Create(account); AccountVerificationDTO av = verificationService.GenerateVerificationCode(account.Email); emailService.SendVerificationEmail(account, av); } catch (Exception e) { if (e.GetType() == typeof(MongoDB.Driver.MongoWriteException) && e.Message.Contains("duplicate key error")) { throw new EmailAlreadyExistsError(); } throw new DatabaseErrorException(); } SetEmailToSession(account.Email); return(account); }