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 MailMessage VerificationEmail(DeveloperAccountDTO account, AccountVerificationDTO verification) { MailMessage msg = new MailMessage(); msg.To.Add(new MailAddress(account.Email, account.FirstName)); msg.From = shrtlnkMailAddress; msg.Subject = "Please verify your email address - shrtlnk"; msg.Body = VerificationEmailBody(account.FirstName, verification.Id); msg.IsBodyHtml = true; return(msg); }
public void UpdateAccount(DeveloperAccountDTO account) { try { account = FindUpdatedFields(account); accountsService.Update(account); } catch { throw new DatabaseErrorException(); } }
private bool IsCurrentUserAppOwner(DeveloperApplicationDTO app) { try { DeveloperAccountDTO currentUser = auth.CurrentUser; return(currentUser.Email == app.DeveloperId); } catch { throw new DatabaseErrorException(); } }
public IActionResult EditAccount() { logger.Info("Developer Portal: EditAccount - Requested"); if (auth.IsSignedIn) { ViewData["Title"] = "Edit Account"; DeveloperAccountDTO account = auth.CurrentUser; logger.Info("Developer Portal: EditAccount - Requested - Account Info", account.ForLogging()); return(View(new EditAccountViewModel(account))); } logger.Info("Developer Portal: EditAccount - Requested - Not Signed In"); return(RedirectToAction("SignIn")); }
public IActionResult SignIn(SignInForm signInForm) { logger.Info("Developer Portal: SignIn - Posted"); try { DeveloperAccountDTO account = auth.AuthenticateUser(signInForm); logger.Info("Developer Portal: SignIn - Posted - Successfully Signed In", account.ForLogging()); return(RedirectToAction("AccountHome")); } catch (Exception e) { logger.Info("Developer Portal: SignIn - Posted ERROR", e); return(View()); } }
public bool SendVerificationEmail(DeveloperAccountDTO account, AccountVerificationDTO verification) { try { using (MailMessage msg = templates.VerificationEmail(account, verification)) { SendMessage(msg); } return(true); } catch (Exception e) { return(false); } }
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); }
public DeveloperAccountDTO AuthenticateUser(SignInForm signInForm) { DeveloperAccountDTO account = accountsService.Get(signInForm.Email); if (account == null || string.IsNullOrEmpty(account.Email)) { throw new AccountNotFoundException(); } bool correctPassword = passwordService.VerifyPassword(account.Password, signInForm.Password); if (!correctPassword) { throw new IncorrectPasswordException(); } SetEmailToSession(account.Email); return(account); }
private DeveloperAccountDTO FindUpdatedFields(DeveloperAccountDTO updates) { DeveloperAccountDTO updatedAccount = CurrentUser; if (!string.IsNullOrWhiteSpace(updates.FirstName)) { updatedAccount.FirstName = updates.FirstName; } if (!string.IsNullOrWhiteSpace(updates.LastName)) { updatedAccount.LastName = updates.LastName; } if (!string.IsNullOrWhiteSpace(updates.Role)) { updatedAccount.Role = updates.Role; } return(updatedAccount); }
public EditAccountViewModel(DeveloperAccountDTO account) { this.Account = account; this.ChangePasswordForm = new ChangePasswordForm(); }