Ejemplo n.º 1
0
        public IActionResult VerifyEmail(int userId, string code)
        {
            var cus    = TheRepository.VerifyAccountProvider(userId, code);
            int result = 0;

            if (cus != null)
            {
                result = 1;
                string body   = "Your account has been verified now you can login successfully.";
                var    model2 = new Emailmodel
                {
                    Name = cus.FirstName,
                    Body = body
                };
                var renderedHTML = ControllerExtensions.RenderViewAsHTMLString(this, "_VerifyEmail.cshtml", model2);

                EmailManager.SendEmail2(cus.EmailAddress, "Account Verified", renderedHTML.Result);
            }
            else
            {
                result = 0;
            }
            ViewBag.result = result;
            return(View());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> sendEmails(int Id)
        {
            try
            {
                var templateData = db.Template.Where(x => x.Id == Id).FirstOrDefault();
                if (templateData != null)
                {
                    var data = getEmails();
                    var html = System.IO.File.ReadAllText(environment.WebRootPath + "/Template/Newsletter.html");

                    html = html.Replace("{{TemplateContent}}", templateData.TemplateContent);
                    foreach (var item in data)
                    {
                        Emailmodel emailmodel = new Emailmodel();
                        emailmodel.From    = templateData.SenderEmail;
                        emailmodel.Subject = templateData.TemplateSubject;

                        emailmodel.To = item;
                        // emailmodel.Body = "Subject : Congratulations !! User " + sendingdetails.UserName + " has bought " + productName + "Hello " + venderName + "Thank you for selling with us, we will like to know you that user " + sendingdetails.UserName + "has bought your products " + productName + "The product need to be shipped today by the end of the day. In case of any delay and emergencies please contact PISTIS Support/Inventory team.Before you shipped the product please don’t forget to read about the terms and conditions for shipping the product so that we can take care of your parcel. (www.pistis,com,mx/termsandconditions)Order details are indicated below: Product Sku :"+ productSku + "Quantity :"+ quatity+ "Payment Status : Approved You will receive another email with the shipment label that the user has opted for, print the label along with the PISTIS sticker and drop it to the nearest DHL/FedexEx center. In case if you want to schedule a pickup please reach out to our support/inventory team on (55 6269 1919 ) WhatsApp : 33 1559 6751 / 55 4058 9672 Thank you for selling with us!!!!!!!!!! Regards,TEAM PISTIS Mexico Comprar Con Confianza";
                        emailmodel.Body = html;
                        emailmodel.key  = "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";
                        await Example.Execute(emailmodel);
                    }
                }
                return(Ok());
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Ejemplo n.º 3
0
        public async Task <IHttpActionResult> RequestPasswordReset(RequestPasswordResetViewModel model)
        {
            // Validates the received email address based on the view model
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // Gets the user entity for the specified email address
            var user = await _repo.FindByEmailAsync(model.Email);

            if (user != null)
            {
                // Generates a password reset token for the user
                string code = await _repo.GeneratePasswordResetTokenAsync(user.Id);

                code = HttpUtility.UrlEncode(code);
                Emailmodel emailmodel = new Emailmodel()
                {
                    From = ConfigurationManager.AppSettings["Sender"], To = model.Email, Subject = Constants.Contants.ChangePassWordSubject, Body = ""
                };
                EmailSender emailSender = new EmailSender();
                var         callBackUrl = string.Format("https://{0}/doi-mat-khau?token={1}&email={2}", Request.RequestUri.Authority, code, model.Email);
                emailmodel.Body = EmailSender.GetContentResetPassword(HostingEnvironment.MapPath(Constants.Contants.AccountRecoveryTemplateUrl), callBackUrl);
                await emailSender.Execute(emailmodel.From, emailmodel.To, emailmodel.Subject, "", emailmodel.Body);

                return(Ok());
            }
            // Displays a view asking the visitor to check their email and click the password reset link
            return(BadRequest());
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> SendgridEmailSubmit(Emailmodel emailmodel)
        {
            ViewData["Message"] = "Email Sent!!!...";
            Example emailexample = new Example();
            await emailexample.Execute(emailmodel.From, emailmodel.To, emailmodel.Subject, emailmodel.Body
                                       , emailmodel.Body);

            return(View("SendgridEmail"));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> RegisterCustomer(RegisterCustomer model)
        {
            var user          = new User();
            var salt          = CommonFunctions.CreateSalt(64); //Generate a cryptographic random number.
            var hashAlgorithm = new SHA512HashAlgorithm();
            var data          = db.Users.Where(x => x.Email == model.Email && x.IsActive == true && x.RoleId == 1).FirstOrDefault();

            if (data == null)
            {
                user = new User()
                {
                    FirstName    = model.FirstName,
                    MiddleName   = model.MiddleName,
                    LastName     = model.LastName,
                    Email        = model.Email,
                    Phone        = model.Phone,
                    PasswordHash = hashAlgorithm.GenerateSaltedHash(CommonFunctions.GetBytes(model.Password), salt),
                    PasswordSalt = salt,
                    RoleId       = 1,
                    IsVerified   = true,
                    IsActive     = true,
                    DateTime     = DateTime.Now
                };
                db.Users.Add(user);
                db.SaveChanges();
                MailAddress objFrom = new MailAddress(_settings.Value.ADMINEMAIL, "info@eschedule");
                MailMessage mailMsg = new MailMessage();
                mailMsg.From = objFrom;
                var html = System.IO.File.ReadAllText(environment.WebRootPath + "/Template/UserRegister.html");

                html = html.Replace("{{userName}}", user.FirstName);
                Emailmodel emailmodel = new Emailmodel();
                emailmodel.From    = "";
                emailmodel.To      = user.Email;
                emailmodel.Subject = " Congratulations, Registered Successfully";
                emailmodel.Body    = html;
                emailmodel.key     = "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";
                await Example.Execute(emailmodel);

                user.ReturnCode    = 0;
                user.ReturnMessage = "You are registered successfully";
            }
            else
            {
                user.ReturnCode    = -1;
                user.ReturnMessage = "Email is already registered";
            }
            try
            {
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(Ok(user));
        }
Ejemplo n.º 6
0
        public ActionResult _VerifyEmail(string name, string link)
        {
            var model = new Emailmodel
            {
                Body = link,
                Name = name
            };

            return(View(model));
        }
Ejemplo n.º 7
0
        public IActionResult SendgridEmailSubmit(Emailmodel emailmodel)
        {
            var userId           = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
            var healthEnthusiast = _context.Health_Enthusiasts.Where(c => c.IdentityUserId ==
                                                                     userId).FirstOrDefault();

            emailmodel.To = healthEnthusiast.Email;
            _context.Emails.Add(emailmodel);
            _context.SaveChanges();
            return(View());
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> forgotpassword1(int Id)
        {
            ApiResult result = new ApiResult();
            var       user   = db.Users.FirstOrDefault(x => x.Id == Id);

            if (user != null)
            {
                user.Password        = CreateRandomPassword(7);
                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();
                result.success = true;
                result.message = "your password has been updated successfully.";
                Emailmodel emailmodel = new Emailmodel();
                emailmodel.From    = "";
                emailmodel.To      = user.Email;
                emailmodel.Subject = "Forgot Password";
                // emailmodel.Body = "As you requested, your password for your account has now been reset.<br/> Your new password is <b>" + user.Password + "</b> .<br/> If it was not at your request, then please contact support immediately.";
                emailmodel.Body = "Dear " + user.FirstName + " Your One Time Password(OTP) for resetting the password for your pistis.com.mx profile is " + user.Otp + "Please enter this code in the OTP code box listed on the page.Note: Please note that this will be valid for the next few minutes only.contact: support @pistis.com.mx if you are unable to reset.Regards,PISTIS Mexico Team";
                emailmodel.key  = "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";
                await Example.Execute(emailmodel);

                // MailAddress objFrom = new MailAddress(1.Value.ADMINEMAIL, "info@eschedule");
                MailMessage mailMsg = new MailMessage();
                // mailMsg.From = objFrom;
                mailMsg.To.Add(new MailAddress(user.Email));
                mailMsg.Subject    = "Forgot Password";
                mailMsg.IsBodyHtml = true;
                mailMsg.Body       = "As you requested, your password for your account has now been reset.<br/> Your new password is <b>" + user.Password + "</b> .<br/> If it was not at your request, then please contact support immediately.";
                //"Dear " + user.FirstName + " " + user.LastName + ",<br/>" + " Your have requested the forgot password, your new password is <b>" + user.Password + "</b>.";

                SmtpClient ObjSmtpClient = new SmtpClient(_settings.Value.SMTPADDRESS, 587);
                ObjSmtpClient.Credentials = new System.Net.NetworkCredential(_settings.Value.SMTPUSERNAME.ToString(), _settings.Value.SMTPPASSWORD.ToString());
                ObjSmtpClient.EnableSsl   = true;
                // ObjSmtpClient.UseDefaultCredentials = false;
                ObjSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
                try
                {
                    ObjSmtpClient.Send(mailMsg);
                }
                catch (Exception ex)
                {
                    result.success = false;
                    result.message = ex.Message;
                }
            }
            else
            {
                result.success = false;
                result.message = "sorry, your account is not valid.";
            }
            return(Ok(result));
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> generateOtp(int UserId, string Email)
        {
            var email = "";
            var check = new User();

            try
            {
                check = db.Users.Where(x => x.Id == UserId && x.RoleId == 1 && x.IsActive == true).FirstOrDefault();
                if (check != null)
                {
                    check.Otp = GenerateNumericOTP();
                    db.SaveChanges();
                    if (check != null)
                    {
                        var html = System.IO.File.ReadAllText(environment.WebRootPath + "/Template/otp.html");

                        html = html.Replace("{{userName}}", check.FirstName);
                        html = html.Replace("{{otp}}", check.Otp);

                        Emailmodel emailmodel = new Emailmodel();
                        emailmodel.From    = "";
                        emailmodel.To      = Email;
                        emailmodel.Subject = "One Time Password";
                        //   emailmodel.Body = "As you requested, your One Time Password for your account has now been reset." + check.Otp + " .If it was not at your request, then please contact support immediately.";
                        emailmodel.Body = html;
                        emailmodel.key  = "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";
                        //   SmtpClient ObjSmtpClient = new SmtpClient(_settings.Value.SMTPADDRESS, 587);
                        // ObjSmtpClient.Credentials = new System.Net.NetworkCredential(_settings.Value.SMTPUSERNAME.ToString(), _settings.Value.SMTPPASSWORD.ToString());
                        // ObjSmtpClient.EnableSsl = true;
                        // var key = _settings.Value.SENDGRID_API_KEY;

                        await Example.Execute(emailmodel);

                        //  ObjSmtpClient.UseDefaultCredentials = false;
                        //  ObjSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
                        try
                        {
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                    return(Ok(check));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(Ok(0));
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> SendgridEmailSubmit2(Emailmodel emailmodel)
        {
            var userId           = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
            var healthEnthusiast = _context.Health_Enthusiasts.Where(c => c.IdentityUserId ==
                                                                     userId).FirstOrDefault();

            emailmodel.To = healthEnthusiast.Email;

            ViewData["Message"] = "Email Sent!!!...";
            Example emailexample = new Example();
            await emailexample.Execute(emailmodel.To);

            return(RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 11
0
        public IActionResult SignupProcess(ServiceProviderModel model)
        {
            model.isActive = true; // should be after user has validated their email. but temp for now

            model.VerifyCode = Guid.NewGuid().ToString();
            var serviceprovider = TheRepository.CreateServiceProvider(model);

            model.id                     = serviceprovider.id;
            model.emailConfirmed         = false;
            model.isRegistrationApproved = false;
            model.createdDate            = DateTime.Now;
            model.password               = PasswordHash.PasswordHash.CreateHash(model.password).Replace("1000:", String.Empty);

            LoginModel login = new LoginModel
            {
                userName    = model.emailAddress,
                password    = model.password,
                userid      = serviceprovider.id,
                createdDate = DateTime.Now
            };

            var createdLogin = TheRepository.CreateLogin(login);


            var callbackUrl = Url.Action("VerifyEmail", "Signup", new { userId = serviceprovider.id, code = model.VerifyCode }, Request.Scheme, Request.Host.Value + "/ServiceProviderArea");
            var Body        = $"Welcome from I NEED YOUR TIME. Click <a href='{callbackUrl}'>here</a> to confirm your email";

            var model2 = new Emailmodel
            {
                Name = model.firstName,
                Body = Body
            };
            var renderedHTML = ControllerExtensions.RenderViewAsHTMLString(this, "_VerifyEmail.cshtml", model2);

            EmailManager.SendEmail2(model.emailAddress, "VerifyAccount", renderedHTML.Result);
            //Send an authorisation email to the service provider
            //SendSimpleMessage("Welcome from I NEED YOUR TIME", "*****@*****.**").Content.ToString();

            //Send an email to the Administrator with the service provider details
            //SendSimpleMessage("New customer on INYT website", "*****@*****.**").Content.ToString();

            return(View(model));
        }
Ejemplo n.º 12
0
        public ActionResult ThankYou(int id, string referenceid)
        {
            BookingsListModel   model    = new BookingsListModel();
            List <BookingModel> bookings = new List <BookingModel>();

            bookings              = TheRepository.GetAllBookingsByCustomer(id).Where(a => a.bookingReference == referenceid).ToList();
            bookings              = bookings.Where(a => a.bookingFulfilled == false).ToList();
            model.bookings        = bookings;
            model.serviceProvider = TheRepository.GetServiceProvider(model.bookings[0].serviceProviderId);
            model.customer        = TheRepository.GetCustomer(id);

            //Send an authorisation email to the customer
            EmailInfo emailInfo = new EmailInfo();

            emailInfo.Body       = $"Welcome from I NEED YOUR TIME. Please see below for details of the appointment";
            emailInfo.emailType  = "Appointment confirmation";
            emailInfo.IsBodyHtml = true;
            emailInfo.Subject    = "Welcome to INYT";
            emailInfo.ToAddress  = model.customer.emailAddress;
            //_emailManager.SendEmail(emailInfo);
            var model2 = new Emailmodel
            {
                Name = model.customer.firstName,
                Body = emailInfo.Body
            };
            var renderedHTML = ControllerExtensions.RenderViewAsHTMLString(this, "_VerifyEmail.cshtml", model2);

            EmailManager.SendEmail2(model.customer.emailAddress, "VerifyAccount", renderedHTML.Result);

            if (bookings != null)
            {
                foreach (var booking in bookings)
                {
                    booking.bookingFulfilled = true;
                    booking.bookingAccepted  = true;
                    booking.bookingReference = referenceid;
                    TheRepository.UpdateBooking(booking);
                }
            }

            return(View(model));
        }
Ejemplo n.º 13
0
        public IActionResult CustSignupProcess(CustomerModel model)
        {
            model.isActive   = true; // should be after user has validated their email. but temp for now
            model.VerifyCode = Guid.NewGuid().ToString();

            var exist = TheRepository.CheckEmailExist(model.emailAddress);

            if (exist)
            {
                TempData["exist"] = "Email Exists";
                return(View("CustSignup", model));
            }
            var customer = TheRepository.CreateCustomer(model);

            model.id                     = customer.id;
            model.emailConfirmed         = false;
            model.isRegistrationApproved = false;
            model.createdDate            = DateTime.Now;

            model.password = PasswordHash.PasswordHash.CreateHash(model.password).Replace("1000:", String.Empty);

            LoginModel login = new LoginModel
            {
                userName    = model.emailAddress,
                password    = model.password,
                userid      = customer.id,
                createdDate = DateTime.Now
            };

            var createdLogin = TheRepository.CreateLogin(login);

            var encryptedid = EncryptionUtility.Encrypt(createdLogin.id.ToString());

            //Send an authorisation email to the customer
            EmailInfo emailInfo   = new EmailInfo();
            var       callbackUrl = Url.Action("VerifyEmail", "CustomerSignup", new { userId = customer.id, code = model.VerifyCode }, Request.Scheme, Request.Host.Value + "/CustomerArea");

            emailInfo.Body       = $"Welcome from I NEED YOUR TIME. Click <a href='{callbackUrl}'>here</a> to confirm your email";
            emailInfo.emailType  = "WelcomeEmail";
            emailInfo.IsBodyHtml = true;
            emailInfo.Subject    = "Welcome to INYT";
            emailInfo.ToAddress  = model.emailAddress;
            //_emailManager.SendEmail(emailInfo);
            var model2 = new Emailmodel
            {
                Name = model.firstName,
                Body = emailInfo.Body
            };
            var renderedHTML = ControllerExtensions.RenderViewAsHTMLString(this, "_VerifyEmail.cshtml", model2);

            EmailManager.SendEmail2(model.emailAddress, "VerifyAccount", renderedHTML.Result);
            //SendSimpleMessage(String.Format("<strong>Welcome from I NEED YOUR TIME. Click <a href='CustomerSignup/ConfirmEmail/{0}'>here</a> to confirm your email", "*****@*****.**"), encryptedid).Content.ToString();

            //Send an email to the Administrator with the customer details
            //EmailInfo emailInfo = new EmailInfo();
            emailInfo.Body       = "New customer on INYT website";
            emailInfo.emailType  = "NewCustomerEmail";
            emailInfo.IsBodyHtml = true;
            emailInfo.Subject    = "New customer";
            emailInfo.ToAddress  = "*****@*****.**";
            _emailManager.SendEmail(emailInfo);
            var model_admin = new Emailmodel
            {
                Name = model.firstName,
                Body = emailInfo.Body
            };
            var renderedHTMLAdmin = ControllerExtensions.RenderViewAsHTMLString(this, "_AdminEmail.cshtml", model_admin);

            EmailManager.SendEmail2(model.emailAddress, "VerifyAccount", renderedHTMLAdmin.Result);

            //SendSimpleMessage("New customer on INYT website", "*****@*****.**").Content.ToString();

            return(View(model));
        }
Ejemplo n.º 14
0
        public IActionResult registerForCheckout(RegisterCustomer model)
        {
            var user          = new User();
            var salt          = CommonFunctions.CreateSalt(64); //Generate a cryptographic random number.
            var hashAlgorithm = new SHA512HashAlgorithm();
            var data          = db.Users.Where(x => x.Email == model.Email && x.IsActive == true && x.RoleId == 1).FirstOrDefault();

            if (data == null)
            {
                user = new User()
                {
                    FirstName    = model.FirstName,
                    MiddleName   = model.MiddleName,
                    LastName     = model.LastName,
                    Email        = model.Email,
                    Phone        = model.Phone,
                    PasswordHash = hashAlgorithm.GenerateSaltedHash(CommonFunctions.GetBytes(model.Password), salt),
                    PasswordSalt = salt,
                    RoleId       = 1,
                    IsVerified   = true,
                    IsActive     = true,
                    DateTime     = DateTime.Now
                };
                db.Users.Add(user);
                db.SaveChanges();
                MailAddress objFrom = new MailAddress(_settings.Value.ADMINEMAIL, "info@eschedule");
                MailMessage mailMsg = new MailMessage();
                mailMsg.From = objFrom;
                var html = System.IO.File.ReadAllText(environment.WebRootPath + "/Template/UserRegister.html");

                html = html.Replace("{{userName}}", user.FirstName);
                Emailmodel emailmodel = new Emailmodel();
                emailmodel.From    = "";
                emailmodel.To      = user.Email;
                emailmodel.Subject = " Congratulations, Registered Successfully";
                emailmodel.Body    = html;
                emailmodel.key     = "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";
                Example.Execute(emailmodel);

                //login code
                LoginModel model1 = new LoginModel();
                var        user1  = db.Users.Where(x => x.Email == user.Email && x.IsVerified == true && x.IsActive == true).Include(x => x.Role).FirstOrDefault();

                if (user1 != null)
                {
                    var newsIsSucbribed = db.Newsletters.Where(x => (x.Email.Trim() == user1.Email.Trim() && x.IsSubscribed == true) || (x.UserId == user1.Id && x.IsSubscribed == true)).FirstOrDefault();

                    if (newsIsSucbribed != null)
                    {
                        model1.IsSubscribed = 1;
                    }
                    else
                    {
                        model1.IsSubscribed = 0;
                    }
                    var result = true;


                    if (result)
                    {
                        // JWT Token
                        var token = new JwtTokenBuilder()
                                    .AddSecurityKey(JwtSecurityKey.Create(_configuration.GetValue <string>("JwtSecretKey")))
                                    .AddIssuer(_configuration.GetValue <string>("JwtIssuer"))
                                    .AddAudience(_configuration.GetValue <string>("JwtAudience"))
                                    .AddExpiry(60)
                                    .AddClaim("Name", user.Email)
                                    .AddRole(user.Role.Name)
                                    .Build();
                        var _refreshTokenObj = new RefreshTokens
                        {
                            Email        = user.Email,
                            Refreshtoken = Guid.NewGuid().ToString(),
                            Revoked      = false,
                        };
                        db.RefreshTokens.Add(_refreshTokenObj);
                        db.SaveChanges();



                        model1.Token        = token.Value;
                        model1.refreshToken = _refreshTokenObj.Refreshtoken;
                        model1.username     = user.FirstName;
                        model1.roleId       = user1.RoleId;
                        model1.success      = true;
                        model1.id           = user1.Id;
                        model1.message      = "login Successful";
                        //}
                    }

                    else
                    {
                        if (user.Email.ToString().Trim() == user.Email.ToString().Trim())
                        {
                            model1.success = false;
                            model1.message = "Invalid password!";
                        }
                        else
                        {
                            model1.success = false;
                            model1.message = "Invalid email address!";
                        }
                    }
                }
                //login code end



                user.ReturnCode    = 0;
                user.ReturnMessage = "You are registered successfully";
            }
            else
            {
                user.ReturnCode    = -1;
                user.ReturnMessage = "Email is already registered";
            }
            try
            {
            }
            catch (Exception ex)
            {
                throw;
            }
            var res = new ResponseModel();

            res.ReturnCode    = user.ReturnCode;
            res.ReturnMessage = user.ReturnMessage;
            res.Id            = user.Id;
            res.FirstName     = user.FirstName;
            res.RoleId        = user.RoleId;
            return(Ok(res));
        }
Ejemplo n.º 15
0
        public async Task <IActionResult> generateOtp(int UserId, string Email)
        {
            var message = 0;
            var email   = "";

            try
            {
                var check = db.Users.Where(x => x.Id == UserId && x.RoleId == 1 && x.IsActive == true).FirstOrDefault();
                if (check != null)
                {
                    check.Otp = GenerateNumericOTP();
                    db.SaveChanges();
                    if (check != null)
                    {
                        MailAddress objFrom = new MailAddress(_settings.Value.ADMINEMAIL, "info@eschedule");
                        MailMessage mailMsg = new MailMessage();
                        mailMsg.From = objFrom;
                        if (check.Email != null)
                        {
                            email = check.Email;
                        }
                        else if (Email != null)
                        {
                            email = Email;
                        }
                        var html = System.IO.File.ReadAllText(environment.WebRootPath + "/Template/otp.html");
                        html               = html.Replace("{{userName}}", check.FirstName);
                        html               = html.Replace("{{otp}}", check.Otp);
                        mailMsg.Body       = html;
                        mailMsg.Subject    = "One Time Password";
                        mailMsg.IsBodyHtml = true;
                        Emailmodel emailmodel = new Emailmodel();
                        emailmodel.From    = "";
                        emailmodel.To      = email;
                        emailmodel.Subject = "One Time Password";
                        emailmodel.Body    = html;
                        emailmodel.key     = _settings.Value.SENDGRID_API_KEY;
                        SmtpClient ObjSmtpClient = new SmtpClient(_settings.Value.SMTPADDRESS, 587);
                        ObjSmtpClient.Credentials = new System.Net.NetworkCredential(_settings.Value.SMTPUSERNAME.ToString(), _settings.Value.SMTPPASSWORD.ToString());
                        ObjSmtpClient.EnableSsl   = true;
                        var key = _settings.Value.SENDGRID_API_KEY;

                        await Example.Execute(emailmodel);

                        //  ObjSmtpClient.UseDefaultCredentials = false;
                        ObjSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
                        try
                        {
                            ObjSmtpClient.Send(mailMsg);
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                    message = 1;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(Ok(message));
        }
Ejemplo n.º 16
0
        public async Task <IActionResult> saveDataAsync([FromBody] spin model)
        {
            try
            {
                if (model != null)
                {
                    if (model.UserId > 0)
                    {
                        var UserSpindata = db.SpinUserData.Where(x => x.UserId == model.UserId).FirstOrDefault();
                        if (UserSpindata == null)
                        {
                            var data = new SpinUserData();
                            data.IsActive           = true;
                            data.SpinCount          = model.SpinCount;
                            data.SpinnerPromotionId = model.SpinnerPromotionId;
                            data.UserId             = model.UserId;
                            data.MoodId             = model.MoodId;
                            data.IsUsed             = false;
                            var date = Convert.ToDateTime(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
                            data.SpinDate      = date;
                            data.CancelCounter = 0;
                            db.SpinUserData.Add(data);
                            db.SaveChanges();
                        }
                        else
                        {
                            UserSpindata.IsActive           = true;
                            UserSpindata.SpinCount          = model.SpinCount;
                            UserSpindata.SpinnerPromotionId = model.SpinnerPromotionId;
                            UserSpindata.UserId             = model.UserId;
                            UserSpindata.MoodId             = model.MoodId;
                            UserSpindata.IsUsed             = false;
                            UserSpindata.CancelCounter      = 0;
                            var date = Convert.ToDateTime(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));

                            UserSpindata.SpinDate = date;
                            db.SaveChanges();
                        }
                        if (model.MoodId == 3)
                        {
                            if (model.SpinnerPromotionId > 0)
                            {
                                var userEmail   = db.Users.Where(x => x.Id == model.UserId).FirstOrDefault();
                                var spinnerdata = db.SpinnerPromotion.Where(x => x.Id == model.SpinnerPromotionId).FirstOrDefault();
                                var url         = "";
                                if (spinnerdata.CategoryId > 0)
                                {
                                    url = "https://www.pistis.com.mx/productcatalogue?Id=" + spinnerdata.CategoryId;
                                    if (spinnerdata.ProductCategoryId > 0)
                                    {
                                        url = "https://www.pistis.com.mx/productcatalogue?Id=" + spinnerdata.ProductCategoryId;
                                        if (spinnerdata.ProductId > 0)//productvarientId
                                        {
                                            var productId = db.ProductVariantDetails.Where(x => x.Id == spinnerdata.ProductId).FirstOrDefault();
                                            url = "https://www.pistis.com.mx/product-details?Id=" + productId.ProductId + "&variantId=" + productId.Id;
                                        }
                                    }
                                }

                                var html = System.IO.File.ReadAllText(environment.WebRootPath + "/Template/Spinner.html");
                                html = html.Replace("{{url}}", url);
                                html = html.Replace("{{Prizename}}", spinnerdata.Description);

                                Emailmodel emailmodel = new Emailmodel();
                                emailmodel.From    = "";
                                emailmodel.To      = userEmail?.Email;
                                emailmodel.Subject = "!Felicidades! Has recibido un cupon PISTIS Mexico.";
                                //  emailmodel.Body = "Mail Subject : Your order from PISTIS.com.mx of" + productName + "Hi  " + sendingdetails.UserName + "Thanks for your order. Your request will be reviewed against availability of inventory, if confirmed you will receive an email with more details. Additional information .The details of your order are indicated below. Your esitmated delivary date is:"+ deliveryDate + "Shipping Type:"+ sendingdetails.shippingType;
                                emailmodel.Body = html;
                                emailmodel.key  = "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";
                                await Example.Execute(emailmodel);
                            }
                        }
                    }
                }
                else
                {
                    var data = new SpinUserData();
                    data.IsActive           = true;
                    data.SpinCount          = model.SpinCount;
                    data.SpinnerPromotionId = model.SpinnerPromotionId;
                    data.UserId             = model.UserId;
                    data.CancelCounter      = 0;
                    db.SpinUserData.Add(data);
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                return(Ok(ex));
            }
            return(Ok());
        }
Ejemplo n.º 17
0
        //Sends different mails to the user depending on what tempData["Action"] Case is.
        public async Task <ActionResult> Email(Emailmodel model)
        {
            var message = new MailMessage();

            message.To.Add(new MailAddress(TempData["Email"].ToString()));
            message.From = new MailAddress("*****@*****.**");


            message.IsBodyHtml = true;
            var body = "";

            switch (TempData["Action"].ToString())
            {
            //Sends a account confirmation link to the user in order to make their account "Active".
            case "Register":
                body            = "<h2>Welcome!</h2> <h3>Please Confirm your account in order to login!</h3> <a href='{0}'>Click here to confirm!</a><p> Regards I,Light</p>";
                message.Body    = string.Format(body, "fww.se/account/VerifyAccount/?query=" + TempData["verifyCode"].ToString());
                message.Subject = "I,Light|Confirm your account!";
                using (var smtp = new SmtpClient())
                {
                    var credentials = new NetworkCredential
                    {
                        UserName = "******",
                        Password = "******"
                    };
                    smtp.Credentials = credentials;
                    smtp.Host        = "smtp.fsdata.se";
                    smtp.Port        = 587;
                    smtp.EnableSsl   = true;

                    await smtp.SendMailAsync(message);

                    TempData["Type"]    = "Success";
                    TempData["Message"] = "Registration succeded! Please check your mail inbox for a confirmation link!";
                    return(RedirectToAction("login", "Account"));
                }

                break;
            //Sends a Reset password link to the user in order to being enable to reset their password.

            case "resetPassword":
                body            = "<h2>A request to reset your password!</h2> <h3>Please click on the following link in order to reset your password!</h3> <a href='{0}'>Click here to reset!</a><p> Regards I,Light</p>";
                message.Body    = string.Format(body, "fww.se/account/verifyReset/?query=" + TempData["resetCode"].ToString());
                message.Subject = "I,Light|Reset your password!";
                using (var smtp = new SmtpClient())
                {
                    var credentials = new NetworkCredential
                    {
                        UserName = "******",
                        Password = "******"
                    };
                    smtp.Credentials = credentials;
                    smtp.Host        = "smtp.fsdata.se";
                    smtp.Port        = 587;
                    smtp.EnableSsl   = true;

                    await smtp.SendMailAsync(message);

                    TempData["Type"]    = "Success";
                    TempData["Message"] = "Reset password successfully! An email has been sent to your inbox. ";
                    return(RedirectToAction("login", "Account"));
                }
                break;
            }
            return(View());
        }
Ejemplo n.º 18
0
        public async Task <User> RegisterVendor(RegisterVendor model)
        {
            JsonResult response      = null;
            var        user          = new User();
            var        salt          = CommonFunctions.CreateSalt(64); //Generate a cryptographic random number.
            var        hashAlgorithm = new SHA512HashAlgorithm();
            var        data          = db.Users.Where(x => (x.Email == model.Email || x.Company.Name == model.Company) && x.IsActive == true && x.RoleId == 2).Include(x => x.Company).FirstOrDefault();

            if (data == null)
            {
                try {
                    //state
                    var states = db.States.Where(x => x.IsActive == true).ToList();
                    if (model.State != null)
                    {
                        var state = states.Where(x => x.Name.ToLower().Trim().Equals(model.State.ToLower().Trim())).FirstOrDefault();
                        if (state != null)
                        {
                            model.StateId = state.Id;
                        }
                        else
                        {
                            var enter = new State();
                            enter.IsActive  = true;
                            enter.Name      = model.State;
                            enter.CountryId = Convert.ToInt32(model.CountryId);
                            db.States.Add(enter);
                            db.SaveChanges();
                            model.StateId = enter.Id;
                        }
                    }
                    user = new User()
                    {
                        FirstName    = model.FirstName,
                        MiddleName   = model.MiddleName,
                        LastName     = model.LastName,
                        DisplayName  = model.DisplayName,
                        UserName     = model.UserName,
                        Address      = model.Address,
                        City         = model.City,
                        CountryId    = model.CountryId,
                        StateId      = model.StateId,
                        Email        = model.Email,
                        Phone        = model.Phone,
                        PasswordHash = hashAlgorithm.GenerateSaltedHash(CommonFunctions.GetBytes(model.Password), salt),
                        PasswordSalt = salt,
                        RoleId       = 2,
                        IsVerified   = true,
                        IsActive     = true,
                        FacebookId   = model.FacebookId,
                        TwitterId    = model.TwitterId,
                        GenderId     = model.GenderId,
                        LanguageId   = model.LanguageId,
                        PostalCode   = model.PostalCode,
                        DOB          = model.DOB,
                        VendorId     = "Pistis_sno_" + model.Company,
                        RFC          = model.RFC
                    };
                    if (model.Image != null && model.Image != "")
                    {
                        var imageResponse = await S3Service.UploadObject(model.Image);

                        response = new JsonResult(new object());

                        if (imageResponse.Success)
                        {
                            user.Image = $"https://pistis.s3.us-east-2.amazonaws.com/{imageResponse.FileName}";
                        }
                    }
                    var com = new Company();
                    if (model.Logo != null && model.Logo != "")
                    {
                        var imageResponse = await S3Service.UploadObject(model.Logo);

                        response = new JsonResult(new object());

                        if (imageResponse.Success)
                        {
                            com.Logo = $"https://pistis.s3.us-east-2.amazonaws.com/{imageResponse.FileName}";
                        }
                    }
                    com.IsActive = true;
                    com.Name     = model.Company;
                    db.Companies.Add(com);
                    db.SaveChanges();
                    user.CompanyId = com.Id;
                    db.Users.Add(user);
                    db.SaveChanges();

                    var proof = new Models.VendorIDProof();
                    if (model.IdProof != null && model.IdProof != "")
                    {
                        var imageResponse = await S3Service.UploadObject(model.IdProof);

                        response = new JsonResult(new object());
                        if (imageResponse.Success)
                        {
                            proof.Proof    = $"https://pistis.s3.us-east-2.amazonaws.com/{imageResponse.FileName}";
                            proof.UserId   = user.Id;
                            proof.IsActive = true;
                            db.VendorIDProof.Add(proof);
                            db.SaveChanges();
                        }
                    }
                    //email
                    if (user.Id != 0)
                    {
                        MailAddress objFrom = new MailAddress(_settings.Value.ADMINEMAIL, "info@eschedule");
                        MailMessage mailMsg = new MailMessage();
                        mailMsg.From = objFrom;
                        var html = System.IO.File.ReadAllText(environment.WebRootPath + "/Template/vendorRegister.html");

                        html = html.Replace("{{userName}}", user.FirstName);
                        Emailmodel emailmodel = new Emailmodel();
                        emailmodel.From    = "";
                        emailmodel.To      = user.Email;
                        emailmodel.Subject = " Congratulations, Registered Successfully";
                        emailmodel.Body    = html;
                        emailmodel.key     = "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";
                        await Example.Execute(emailmodel);
                    }

                    var result = new User();
                    result.ReturnCode    = 0;
                    result.ReturnMessage = "You are registered successfully";
                    return(result);
                }
                catch (Exception ex)
                {
                    user.ReturnCode    = -1;
                    user.ReturnMessage = ex.Message;
                    return(user);
                }
            }
            else
            {
                user.ReturnCode = -1;
                if (data.Email == model.Email)
                {
                    user.ReturnMessage = "Email is already registered";
                }
                else if (data.Company.Name == model.Company)
                {
                    user.ReturnMessage = "Company is already registered";
                }
                else
                {
                    user.ReturnMessage = "Something went Wrong";
                }
                return(user);
            }
        }