Esempio n. 1
0
        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());
            }
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
 public void UpdateAccount(DeveloperAccountDTO account)
 {
     try
     {
         account = FindUpdatedFields(account);
         accountsService.Update(account);
     }
     catch
     {
         throw new DatabaseErrorException();
     }
 }
Esempio n. 4
0
 private bool IsCurrentUserAppOwner(DeveloperApplicationDTO app)
 {
     try
     {
         DeveloperAccountDTO currentUser = auth.CurrentUser;
         return(currentUser.Email == app.DeveloperId);
     }
     catch
     {
         throw new DatabaseErrorException();
     }
 }
Esempio n. 5
0
 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"));
 }
Esempio n. 6
0
 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());
     }
 }
Esempio n. 7
0
 public bool SendVerificationEmail(DeveloperAccountDTO account, AccountVerificationDTO verification)
 {
     try
     {
         using (MailMessage msg = templates.VerificationEmail(account, verification))
         {
             SendMessage(msg);
         }
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        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);
        }
Esempio n. 11
0
 public EditAccountViewModel(DeveloperAccountDTO account)
 {
     this.Account            = account;
     this.ChangePasswordForm = new ChangePasswordForm();
 }