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

                if (user == null || !(await UserManager.IsEmailConfirmedAsync(user.Id)))
                {
                    ModelState.AddModelError("", "The email either does not exist or is not confirmed.");
                    return(View());
                }

                // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                // Send an email with this link
                string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);

                var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                var body        = "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a> <br/> or copy the following web address and paste into your browser<br/>" + callbackUrl;
                TMSendEmail.send("*****@*****.**", "Zimpapers Classifieds", user.Email, "Zimpapers Classifieds password recovery", body, null);
                // await UserManager.SendEmailAsync(user.Id, "Reset Password", "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>");
                return(RedirectToAction("ForgotPasswordConfirmation", "Account"));
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
 public ActionResult Contact(GeneralEmailViewModel model)
 {
     if (ModelState.IsValid)
     {
         model.EmailTo = "*****@*****.**";
         TMSendEmail.send(model.EmailFrom, model.Name, model.EmailTo, model.Subject, "<strong>Sender : " + model.Name + " (" + model.EmailFrom + ")</strong> <br/><br/>" + model.Body, model.CopyEmail);
         ViewBag.Message = "Message sent successfully. Thank you for your message.";
     }
     return(View(model));
 }
        public async Task <ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            ViewBag.searchViewModel = new ListingSearchViewModel();
            if (User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Manage"));
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();

                if (info == null)
                {
                    return(View("ExternalLoginFailure"));
                }

                var user = new ApplicationUser()
                {
                    UserName = model.Email, Email = model.Email, PhoneNumber = model.ClassifiedsPhone, Address = model.Address, FullName = model.FullName, Alias = model.Alias
                };
                IdentityResult result = await UserManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    //add this user to Registered role
                    var idManager = new IdentityManager();
                    // idManager.ClearUserRoles(user.Id);
                    idManager.AddUserToRole(user.Id, "Registered");
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);

                    if (result.Succeeded)
                    {
                        await SignInAsync(user, isPersistent : true);

                        // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                        // Send an email with this link
                        string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                        var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                        var body        = "Please confirm your Zimpapers Classifieds account by clicking  <a href=\"" + callbackUrl + "\">here</a><br/><br/> or copy the following address and paste into your browser if click does not work.<br/>" + callbackUrl;
                        TMSendEmail.send("*****@*****.**", "Zimpapers Classifieds", user.Email, "New Zimpapers Classifieds account confirmation", body, null);

                        return(RedirectToLocal(returnUrl));
                    }
                }
                AddErrors(result);
            }
            ViewBag.ReturnUrl = returnUrl;
            return(View(model));
        }
Beispiel #4
0
        public ActionResult contactseller(CreateMessageViewModel model)
        {
            var listingQ = from l in db.Listings.Include("Owner")
                           where l.ListingId == model.ListingId
                           select l;
            var listing = listingQ.FirstOrDefault();

            if (listing == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            if (ModelState.IsValid)
            {
                var     userId  = User.Identity.GetUserId();
                Message message = new Message();
                message.Detail      = model.Detail;
                message.ListingId   = model.ListingId;
                message.Phone       = model.Phone;
                message.SenderEmail = model.SenderEmail;
                if (!String.IsNullOrEmpty(userId))
                {
                    message.SenderId = userId;
                }
                message.SenderName = model.SenderName;
                message.Subject    = model.Subject;
                message.Type       = "listing";
                message.Created    = DateTime.Now;
                message.Updated    = DateTime.Now;
                db.Messages.Add(message);
                db.SaveChanges();
                ViewBag.Message = "Message sent to seller successfully. Thank you for your message. ";

                var user = db.Users.Find(userId);
                if (user != null)
                {
                    model.ListingId   = listing.ListingId;
                    model.Phone       = user.ClassifiedsPhone;
                    model.SenderEmail = user.Email;
                    model.SenderName  = user.Alias ?? user.FullName;
                }
                model.Subject = "About listing #" + listing.ListingId + " - " + listing.Title;
                //now send the email.
                //TMSendEmail.send(model.SenderEmail, model.SenderName, listing.Owner.Email, model.Subject, model.Detail, null);
                TMSendEmail.send(model.SenderEmail, "Zimpapers Classifieds", "*****@*****.**", model.Subject,
                                 "<strong>Phone : " + model.Phone + "<strong><br/><strong>Name: " + model.SenderName + "</strong><br/>" + model.Detail, null);
            }
            ViewBag.Listing = listing;
            return(View(model));
        }
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser()
                {
                    UserName = model.Email,
                    Email    = model.Email,
                    FullName = model.FullName,
                    //DOB = model.DOB,
                    //Sex = model.Sex,
                    Alias            = model.Alias,
                    ClassifiedsPhone = model.ClassifiedsPhone,
                    Address          = model.Address
                };
                IdentityResult result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    //add this user to Registered role
                    var idManager = new IdentityManager();
                    // idManager.ClearUserRoles(user.Id);
                    idManager.AddUserToRole(user.Id, "Registered");
                    // await SignInAsync(user, isPersistent: true);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                    var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    var body        = "Please confirm your Zimpapers Classifieds account by clicking  <a href=\"" + callbackUrl + "\">here</a><br/><br/> or copy the following address and paste into your browser if click does not work.<br/>" + callbackUrl;
                    TMSendEmail.send("*****@*****.**", "Zimpapers Classifieds", user.Email, "New Zimpapers Classifieds account confirmation", body, null);
                    //await UserManager.SendEmailAsync(user.Id, "Confirm your Zimpapers Classifieds new account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("tokensent", "account"));
                }
                else
                {
                    AddErrors(result);
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }