Exemplo n.º 1
0
        public ActionResult FirstTimeLogin(int step = 1, bool success = true, string status = "OK", string accNo = "", string email = "")
        {
            ViewBag.step    = step;
            ViewBag.success = success;
            ViewBag.status  = status;

            var encodedEmail = Convert.ToBase64String(Encoding.UTF8.GetBytes(email));
            var decodedEmail = string.Empty;

            try
            {
                decodedEmail = Encoding.UTF8.GetString(Convert.FromBase64String(email));
            }
            catch (Exception)
            {
                return(RedirectToAction("first-time-login/step/1", "ost-account"));
            }
            var estData = new EstUserInputModel
            {
                AccountNo = accNo
            };

            if (step == 2)
            {
                if (!IsValidEmail(decodedEmail))
                {
                    return(RedirectToAction("first-time-login/step/1", "ost-account", new { success = false, status = $"Your registered email address is invalid.", accNo = accNo, email = encodedEmail }));
                }
                var tempEmail = Regex.Split(decodedEmail, "@");
                for (var i = 0; i < decodedEmail.Length; i++)
                {
                    var frontEmail      = tempEmail[0];
                    var changeFront     = "";
                    var hashedFront     = "";
                    var frontEmailAfter = "";
                    if (frontEmail.Length > 3)
                    {
                        changeFront     = frontEmail.Substring(2, (frontEmail.Length - 3));
                        hashedFront     = Regex.Replace(changeFront, @"[\w]", "*");
                        frontEmailAfter = frontEmail.Substring(0, 2) + hashedFront + frontEmail.Substring(frontEmail.Length - 1);
                    }
                    else
                    {
                        changeFront     = frontEmail.Substring(1, (frontEmail.Length - 1));
                        hashedFront     = Regex.Replace(changeFront, @"[\w]", "*");
                        frontEmailAfter = frontEmail.Substring(0, 0) + hashedFront + frontEmail.Substring(frontEmail.Length - 1);
                    }

                    var    endEmail      = tempEmail[1];
                    var    changeEnd     = endEmail.Substring(2, (endEmail.Length - 4));
                    var    hashedEnd     = Regex.Replace(changeEnd, @"[\w]", "*");
                    string endEmailAfter = endEmail.Substring(0, 2) + hashedEnd + endEmail.Substring(endEmail.Length - 2);

                    estData.HintEmailAddress = (frontEmailAfter + "@" + endEmailAfter);
                }
            }
            return(View(estData));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> FirstTimeLogin(int step, EstUserInputModel model)
        {
            var pointingUrl  = $"/api/est-registration/" + model.AccountNo;
            var outputString = await m_baseUrlClient.GetAsync(pointingUrl);

            var output       = string.Empty;
            var errorMessage = "Please go to the nearest Pusat Pos Laju (PPL) to reactivate your account.";

            if (outputString.IsSuccessStatusCode)
            {
                output = await outputString.Content.ReadAsStringAsync();

                var item         = JsonConvert.DeserializeObject <EstRegisterModel>(output);
                var encodedEmail = Convert.ToBase64String(Encoding.UTF8.GetBytes(item.EmailAddress));
                if (step == 1)
                {
                    if (model.AccountNo == item.AccountNo)
                    {
                        if (item.AccountStatus == 0)
                        {
                            if (item.EmailAddress != null)
                            {
                                if (IsValidEmail(item.EmailAddress))
                                {
                                    return(RedirectToAction("first-time-login/step/2", "ost-account", new { accNo = item.AccountNo, email = encodedEmail }));
                                }
                                else
                                {
                                    return(RedirectToAction("first-time-login/step/1", "ost-account", new { success = false, status = $"Your registered email address is invalid. {errorMessage}", accNo = item.AccountNo, email = encodedEmail }));
                                }
                            }
                            else
                            {
                                return(RedirectToAction("first-time-login/step/1", "ost-account", new { success = false, status = $"Your registered email address is invalid. {errorMessage}", accNo = item.AccountNo, email = encodedEmail }));
                            }
                        }
                        else if (item.AccountStatus == 1)
                        {
                            return(RedirectToAction("first-time-login/step/1", "ost-account", new { success = false, status = $"Your account has been blocked. {errorMessage}", accNo = item.AccountNo, email = encodedEmail }));
                        }
                        else
                        {
                            return(RedirectToAction("first-time-login/step/1", "ost-account", new { success = false, status = $"Your account has been terminated. {errorMessage}", accNo = item.AccountNo, email = encodedEmail }));
                        }
                    }
                    else
                    {
                        return(RedirectToAction("first-time-login/step/1", "ost-account", new { success = false, status = $"Your account number is invalid. {errorMessage}", accNo = item.AccountNo, email = encodedEmail }));
                    }
                }
                else if (step == 2)
                {
                    if (IsValidEmail(model.EmailAddress) && IsValidEmail(item.EmailAddress))
                    {
                        if ((model.EmailAddress != item.EmailAddress) ||
                            (model.AccountNo != item.AccountNo))
                        {
                            return(RedirectToAction("first-time-login/step/2", "ost-account", new { success = false, status = $"Your email address cannot be verified. {errorMessage}", accNo = item.AccountNo, email = encodedEmail }));
                        }
                    }
                    else
                    {
                        return(RedirectToAction("first-time-login/step/1", "ost-account", new { success = false, status = $"Your registered email address is invalid. {errorMessage}", accNo = item.AccountNo, email = encodedEmail }));
                    }

                    //register customer as Ezisend user; designation - "Contract customer"
                    string password      = Membership.GeneratePassword(8, 1);
                    var    registerModel = new OstRegisterModel
                    {
                        UserName        = model.AccountNo,
                        FullName        = item.CustomerName,
                        Password        = password,
                        ConfirmPassword = password,
                        Email           = model.EmailAddress,
                        Designation     = "Contract customer"
                    };
                    var result = await CreateAccount(registerModel);

                    if (!result.Success)
                    {
                        return(RedirectToAction("first-time-login/step/1", "ost-account", new { success = result.Success, status = result.Status, accNo = item.AccountNo, email = encodedEmail }));
                    }

                    var emailModel = new OstCreateEmailModel
                    {
                        UserEmail    = registerModel.Email,
                        UserName     = registerModel.UserName,
                        EmailSubject = "Create your password",
                        EmailBody    = $"Thank you for registering as a Pos Laju Business Customer user at {ConfigurationManager.ApplicationFullName}. To complete your account registration, you must create a new password.",
                    };
                    await SendForgotPasswordEmail(emailModel);

                    //create user details
                    var context    = new SphDataContext();
                    var userDetail = new Bespoke.Ost.UserDetails.Domain.UserDetail();
                    var guid       = Guid.NewGuid().ToString();
                    userDetail.Id     = guid;
                    userDetail.UserId = registerModel.UserName;
                    userDetail.Profile.CompanyName                                 = item.CompanyName;
                    userDetail.Profile.ContactPerson                               = item.CustomerName;
                    userDetail.ProfilePictureUrl                                   = "/assets/admin/pages/img/avatars/user_default.png";
                    userDetail.Profile.ContactInformation.Email                    = registerModel.Email;
                    userDetail.Profile.ContactInformation.ContactNumber            = item.ContactNo;
                    userDetail.Profile.ContactInformation.AlternativeContactNumber = item.AltContactNo;

                    userDetail.Profile.Address.Address1 = item.Address.Address1;
                    userDetail.Profile.Address.Address2 = item.Address.Address2;
                    userDetail.Profile.Address.Address3 = item.Address.Address3;
                    userDetail.Profile.Address.Address4 = $"{item.Address.Address4} {item.Address.Address5}";
                    userDetail.Profile.Address.City     = item.Address.City;
                    userDetail.Profile.Address.State    = item.Address.State;
                    userDetail.Profile.Address.Country  = "MY"; //item.Address.Country;
                    userDetail.Profile.Address.Postcode = item.Address.Postcode;

                    userDetail.PickupAddress.Address.Address1 = item.PickupAddress.Address1;
                    userDetail.PickupAddress.Address.Address2 = item.PickupAddress.Address2;
                    userDetail.PickupAddress.Address.Address3 = item.PickupAddress.Address3;
                    userDetail.PickupAddress.Address.Address4 = $"{item.PickupAddress.Address4} {item.PickupAddress.Address5}";
                    userDetail.PickupAddress.Address.City     = item.PickupAddress.City;
                    userDetail.PickupAddress.Address.State    = item.PickupAddress.State;
                    userDetail.PickupAddress.Address.Country  = "MY"; //item.PickupAddress.Country;
                    userDetail.PickupAddress.Address.Postcode = item.PickupAddress.Postcode;

                    userDetail.BillingAddress.Address.Address1 = item.BillingAddress.Address1;
                    userDetail.BillingAddress.Address.Address2 = item.BillingAddress.Address2;
                    userDetail.BillingAddress.Address.Address3 = item.BillingAddress.Address3;
                    userDetail.BillingAddress.Address.Address4 = $"{item.BillingAddress.Address4} {item.BillingAddress.Address5}";
                    userDetail.BillingAddress.Address.City     = item.BillingAddress.City;
                    userDetail.BillingAddress.Address.State    = item.BillingAddress.State;
                    userDetail.BillingAddress.Address.Country  = "MY"; //item.BillingAddress.Country;
                    userDetail.BillingAddress.Address.Postcode = item.BillingAddress.Postcode;

                    using (var session = context.OpenSession())
                    {
                        session.Attach(userDetail);
                        await session.SubmitChanges("Default");
                    }

                    return(RedirectToAction("success", "ost-account", new { success = true, status = "OK", operation = "register" }));
                }
            }
            else
            {
                return(RedirectToAction("first-time-login/step/1", "ost-account", new { success = false, status = $"Account number {model.AccountNo} is not exist. {errorMessage}" }));
            }
            return(RedirectToAction("first-time-login/step/1", "ost-account"));
        }