Esempio n. 1
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));
        }