public async Task <ActionResult> ForgotPassword(ForgotPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await UserManager.FindByNameAsync(model.Email);

                string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);

                var         callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                var         emailFrom   = WebConfigurationManager.AppSettings["emailfrom"];
                MailMessage mailMessage = new MailMessage(emailFrom, model.Email)
                {
                    Subject    = "Reset Password",
                    Body       = "<p><span style=\"font-family: arial;\">Reset your password by clicking <a href=\"" + callbackUrl + "\">here</a></span></p>.",
                    IsBodyHtml = true
                };

                var service = new EmailConfirm();
                await service.SendAsync(mailMessage);

                return(RedirectToAction("ForgotPasswordConfirmation", "Account"));
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Пример #2
0
        public async Task <ActionResult> Close(EmailConfirm nou, int id)
        {
            string url = Baseurl + "api/announcements/CloseAnnouncement?announcementId=" + id;

            if (ModelState.IsValid)
            {
                HttpClient client = new HttpClient();
                var        result = await client.PostAsJsonAsync(url, nou);

                if (result.IsSuccessStatusCode)
                {
                    nou = await result.Content.ReadAsAsync <EmailConfirm>();

                    ViewBag.Result = "Succesfully saved!";
                    ModelState.Clear();
                    //daca anuntul a fost postat cu succes utilizatorul ajunge din nou la lista de anunturi
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ViewBag.Result = "Error!Please try again with valid email";
                }
            }
            return(View(nou));
        }
Пример #3
0
        protected void SendResetLink_Click(object sender, EventArgs e)
        {
            string email = Email.Text;

            Email.Text = "";
            EmailConfirm.SendEmailForPasswordReset(email);

            ResetTable.Visible       = false;
            ResetPasswordBtn.Visible = false;
            Msg.Text = "Email has been sent, please check your inbox!";
        }
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser
                {
                    UserName    = model.Email,
                    DisplayName = model.DisplayName,
                    Email       = model.Email,
                    FirstName   = model.FirstName,
                    LastName    = model.LastName,
                    AvatarUrl   = WebConfigurationManager.AppSettings["DefaultAvatar"]
                };

                if (UploadHelper.IsWebFriendlyImage(model.Avatar))
                {
                    var fileName = Path.GetFileName(model.Avatar.FileName);
                    model.Avatar.SaveAs(Path.Combine(Server.MapPath("~/Avatars/"), fileName));
                    user.AvatarUrl = "/Avatars/" + fileName;
                }

                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                    var         callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    var         emailFrom   = WebConfigurationManager.AppSettings["emailfrom"];
                    MailMessage mailMessage = new MailMessage(emailFrom, model.Email)
                    {
                        Subject    = "Confirm your account",
                        Body       = "<p><span style=\"font-family: arial;\">Thank you for registering.</span></p><p><span style=\"font-family: arial;\">Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>.</span></p>",
                        IsBodyHtml = true
                    };

                    var service = new EmailConfirm();
                    await service.SendAsync(mailMessage);

                    return(RedirectToAction("EmailConfirmationSent", "Account"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Пример #5
0
        protected void Confirm(string email, string cfmcode)
        {
            switch (EmailConfirm.ValidatePasswordReset(email, cfmcode))
            {
            case EmailConfirmResult.Failed:
                Msg.Text = "Something went wrong with the link, please try again";
                break;

            case EmailConfirmResult.Success:
                Msg.Text      = "Check your email for your new password";
                Msg.ForeColor = System.Drawing.Color.GreenYellow;
                break;

            case EmailConfirmResult.UserNotFound:
            case EmailConfirmResult.OtherError:
                Msg.Text = "User not found or an error has occured";
                break;
            }
        }
Пример #6
0
        public async Task <IActionResult> ConfirmEmail(string uid, string token, string email)
        {
            EmailConfirm model = new EmailConfirm
            {
                Email = email
            };

            if (!string.IsNullOrEmpty(uid) && !string.IsNullOrEmpty(token))
            {
                token = token.Replace(' ', '+');
                var result = await _accountRepository.ConfirmEmailAsync(uid, token);

                if (result.Succeeded)
                {
                    model.EmailVerified = true;
                }
            }

            return(View(model));
        }
Пример #7
0
        protected void Confirm(string email, string cfmcode)
        {
            switch (EmailConfirm.EmailValidate(email, cfmcode))
            {
            case EmailConfirmResult.Failed:
                Msg.Text = "Email address confirmation code failed";
                break;

            case EmailConfirmResult.Success:
                Msg.Text                = "Email address successfully confirmed";
                Msg.ForeColor           = System.Drawing.Color.GreenYellow;
                EmailConfirmBtn.Visible = false;
                ConfirmTable.Visible    = false;
                break;

            case EmailConfirmResult.UserNotFound:
            case EmailConfirmResult.OtherError:
                Msg.Text = "User not found or an error has occured";
                break;
            }
        }
Пример #8
0
        public async Task <IActionResult> ConfirmEmail(EmailConfirm model)
        {
            var user = await _accountRepository.GetUserByEmailAsync(model.Email);

            if (user != null)
            {
                if (user.EmailConfirmed)
                {
                    model.EmailVerified = true;
                    return(View(model));
                }

                await _accountRepository.GenerateEmailConfirmationTokenAsync(user);

                model.EmailSent = true;
                ModelState.Clear();
            }
            else
            {
                ModelState.AddModelError("", "Something went wrong.");
            }
            return(View(model));
        }
Пример #9
0
        public async Task <ActionResult> SendHouseInvitation([Bind(Include = "UserId,Body,Created,SentBy,RecipientEmail")] Invitation invite, string messageBody, string recipient)
        {
            var    time          = DateTimeOffset.Now;
            var    useBy         = time.AddDays(5);
            var    currentUserId = User.Identity.GetUserId();
            var    currentUser   = db.Users.Find(currentUserId);
            var    from          = currentUser.Email;
            var    code          = invite.Code;
            string cb            = Url.Action("AcceptAndRegister", "Account", new { id = invite.HouseholdId, code = code }, protocol: HttpContext.Request.Url.Scheme);

            if (ModelState.IsValid)
            {
                invite.Subject        = $"Invitation From {currentUser.FirstName}";
                invite.SentBy         = currentUser.Email;
                invite.RecipientEmail = recipient;
                invite.TTL            = useBy;
                invite.Code           = Guid.NewGuid();
                invite.HouseholdId    = currentUser.MyHouse.Id;
                invite.IsValid        = true;
                invite.Created        = time;
                invite.Body           = $"{messageBody} <hr /> To join {currentUser.FirstName}'s household, <a href='{cb}' target='_blank'>click here</a>!";
                db.Invitations.Add(invite);

                db.SaveChanges();
            }

            MailMessage mailMessage = new MailMessage(from, invite.RecipientEmail)
            {
                IsBodyHtml = true,
                Subject    = invite.Subject,
                Body       = invite.Body
            };
            var service = new EmailConfirm();
            await service.SendAsync(mailMessage);

            return(RedirectToAction("Dashboard", "Home"));
        }
Пример #10
0
        public void SendConfirmationEmail(string email, HttpRequestBase request, HttpResponseBase response)
        {
            if (String.IsNullOrEmpty(email))
            {
                throw new ArgumentNullException("email");
            }
            MailAddress from = new MailAddress("*****@*****.**");

            try
            {
                from = new MailAddress(this.Config.AdminEmail);
            }
            catch
            {
            }

            MailAddress to;

            try
            {
                to = new MailAddress(email);
            }
            catch
            {
                return;
            }

            using (var message = new MailMessage(from, to))
            {
                String body = this.Config.ConfirmEmailText;

                String subject = this.Config.ConfirmEmailSubject;

                EmailConfirm confirm = new EmailConfirm
                {
                    Email = email,
                    Key   = Guid.NewGuid()
                };
                this.Db.EmailConfirms.InsertOnSubmit(confirm);
                this.Db.SubmitChanges();

                String Link = request.Url.Scheme + Uri.SchemeDelimiter + request.Url.Authority + response.ApplyAppPathModifier("~/Account/Confirm?key=" + confirm.Key);

                try
                {
                    message.Subject    = subject;
                    message.Body       = String.Format(body, Link);
                    message.IsBodyHtml = true;
                }
                catch (FormatException)
                {
                    return;
                }

                try
                {
                    using (var client = new SmtpClient(this.Config.SmtpHost, this.Config.SmtpPort))
                    {
                        client.Send(message);
                    }
                }
                catch
                {
                }
            }
        }
Пример #11
0
        protected void ProfileChange_Click(object sender, EventArgs e)
        {
            string whatschanged = "";

            using (Authenticate a = new Authenticate())
                using (DataContext db = new DataContext())
                {
                    Users u = CurrentUser.Entity(false, db);

                    if (a.ValidateLogin(CfmPasswordTxt.Text) != AuthResult.Success)
                    {
                        Msg.Text = "Your entered password was incorrect!";
                        return;
                    }

                    if (!DobTxt.Text.Equals(u.BirthDate.ToLongDateString()))
                    {
                        DateTime newDob;
                        if (DateTime.TryParse(DobTxt.Text, out newDob))
                        {
                            u.BirthDate   = newDob;
                            whatschanged += "Birthdate ";
                        }
                        else
                        {
                            Msg.Text = "Error with date of birth input!";
                            return;
                        }
                    }

                    // Sequentially check if the details were changed
                    if (!usernameTxt.Text.Equals(u.UserName))
                    {
                        ProfileLogger.Instance.ProfileChange("USERNAME", u.UserName, usernameTxt.Text);
                        u.UserName    = usernameTxt.Text;
                        whatschanged += "Username ";
                    }

                    if (!emailTxt.Text.Equals(u.Email))
                    {
                        ProfileLogger.Instance.ProfileChange("EMAIL", u.Email, emailTxt.Text.ToLower());

                        Users usr = Users.FindByEmail(u.Email.ToLower());
                        if (usr != null)
                        {
                            Msg.Text = "That email is already registered with HackNet";
                            return;
                        }

                        u.Email = emailTxt.Text.ToLower();
                        EmailConfirm.SendEmailForConfirmation(u, db);
                        whatschanged += "Email ";
                    }

                    if (!fnameTxt.Text.Equals(u.FullName))
                    {
                        ProfileLogger.Instance.ProfileChange("FULLNAME", u.FullName, fnameTxt.Text);
                        u.FullName    = fnameTxt.Text;
                        whatschanged += "Name ";
                    }

                    if (!whatschanged.Equals(""))
                    {
                        Msg.ForeColor = System.Drawing.Color.GreenYellow;
                        Msg.Text      = "Changes saved successfully!";
                        if (whatschanged.Contains("Email"))
                        {
                            Msg.Text     += " Kindly check your new email to re-verify";
                            u.AccessLevel = AccessLevel.Unconfirmed;
                            FormsAuthentication.SignOut();
                        }
                        db.SaveChanges();
                    }
                    else
                    {
                        Msg.Text = "No changes were made.";
                    }
                }
        }