Esempio n. 1
0
        public ActionResult ResendInvite(string initiativeid, string code, FormCollection collection)
        {
            var initiative    = _initiativeBusiness.GetInitiative(Guid.Parse(initiativeid));
            var developerRole = initiative.DeveloperRoles.Single(x => x.InviteCode == code);

            var enabled = _settingsBusiness.GetEmailSetting().EMailConfirmationEnabled;

            if (enabled)
            {
                var subject = "A reminder for the invitation to " + initiative.Name + " at www.quilt4.com";
                var message = _initiativeBusiness.GenerateInviteMessage(initiativeid, code, string.Empty, Request.Url);

                try
                {
                    _emailBusiness.SendEmail(new List <string> {
                        developerRole.InviteEMail
                    }, subject, message);
                }
                catch (SmtpException e)
                {
                    TempData["InviteError"] = "Could not connect to the email server";
                    return(RedirectToAction("Member", "Initiative", new { id = initiativeid }));
                }
                catch (Exception e)
                {
                    TempData["InviteError"] = "Something went wrong";
                    return(RedirectToAction("Member", "Initiative", new { id = initiativeid }));
                }
            }

            return(RedirectToAction("Member", "Initiative", new { id = initiativeid }));
        }
Esempio n. 2
0
        public async Task <ActionResult> ChangeEmail(ChangeEmailModel model)
        {
            var username  = _accountRepository.FindById(User.Identity.GetUserId()).UserName;
            var userAsync = await _accountRepository.FindAsync(username, model.Password);

            var allEmails = _accountRepository.GetUsers().Select(x => x.Email).ToArray();

            if (allEmails.Any(x => x.Equals(model.NewEmail)) || userAsync == null)
            {
                if (allEmails.Any(x => x.Equals(model.NewEmail)))
                {
                    ViewBag.EmailAlreadyExist = "Email already exist!!";
                }

                if (userAsync == null)
                {
                    ViewBag.WrongPassword = "******";
                }
                return(View());
            }


            var result = await _accountRepository.UpdateEmailAsync(userAsync.Id, model.NewEmail);

            if (result.Succeeded)
            {
                await _accountRepository.UpdateSecurityStampAsync(userAsync.Id);

                var token = await _accountRepository.GenerateEmailConfirmationTokenAsync(userAsync.Id);

                var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = userAsync.Id, code = token }, protocol: Request.Url.Scheme);
                _emailBusiness.SendEmail(new List <string>()
                {
                    model.NewEmail
                }, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
                //update session cookie
                userAsync = await _accountRepository.FindAsync(username, model.Password);

                AuthenticationManager.SignOut();
                await _accountRepository.PasswordSignInAsync(userAsync.UserName, model.Password, false, false);
            }

            return(Redirect("Index"));
        }
Esempio n. 3
0
        public ActionResult Send(SendEmailViewModel model)
        {
            var success = true;

            try
            {
                _emailBusiness.SendEmail(new List <string> {
                    model.ToEmail
                }, model.Subject, model.Body);
            }
            catch (FormatException e)
            {
                ViewBag.ErrorMessage = "Email adress wrongly formatted";
                success = false;
            }
            catch (SmtpException e)
            {
                ViewBag.ErrorMessage = "Can not connect to SMTP server!";
                success = false;
            }
            catch (ArgumentNullException e)
            {
                ViewBag.ErrorMessage = "Enter an email adress!";
                success = false;
            }
            catch (Exception e)
            {
                ViewBag.ErrorMessage = "Something went wrong!";
                success = false;
            }

            if (success)
            {
                return(RedirectToAction("Index", "Dashboard"));
            }

            return(View(model));
        }
Esempio n. 4
0
 public ActionResult <bool> Post([FromBody] SendEmailModel sendEmailModel)
 {
     return(_emailBusiness.SendEmail(sendEmailModel.DocumentId, sendEmailModel.EmailAddress));
 }