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

                if (user == null || !(await CustomUser.IsEmailConfirmedAsync(user.Id)))
                {
                    // Don't reveal that the user does not exist or is not confirmed
                    return(View("ForgotPasswordConfirmation"));
                }


                // 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 CustomUser.GeneratePasswordResetTokenAsync(user.Id);

                var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                await CustomUser.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 virtual async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                CustomUser customUser = model;
                customUser.TwoFactorEnabled = true;

                var user = await CustomUser.FindByNameAsync(model.Email);

                if (user != null && !user.PersonRoles.Any(r => r.RoleId == model.RoleID))
                {
                    //await CustomUser.AddToRoleAsync(user.Id, Enum.GetName(typeof(DTO.Constants.RolesEnum), model.RoleID));
                    //await CustomUser.AddClaimAsync(user.Id, new Claim(ClaimTypes.Role, model.RoleID.ToString()));

                    int            existingRoleID  = user.PersonRoles.Select(r => r.RoleId).First();
                    var            existedRoleName = existingRoleID == ConstantsDtos.Roles.Customer ? "RF Customer" : "RF Driver";
                    var            RoleName        = model.RoleID == ConstantsDtos.Roles.Customer ? "RF Customer" : "RF Driver";
                    string         loginUrl        = Url.Action(Mvc.Account.Login());
                    IList <string> message         = new List <string>();
                    message.Add(string.Format("We found your email address in our system and you already created an account with us as <strong> {0} </strong>.<br> To create new role please do the following:<ul><ol>Log in to your account.</ol> <ol>Click on Profile link</ol><ol>Click on Add New Role</ol></ul> Click here to go to login page <a class='btn btn-info' href='{loginUrl}'>LogIn</a> ", existedRoleName));

                    TempData["Errors"] = message;
                }
                else
                {
                    var result = await CustomUser.CreateAsync(customUser, model.Password);

                    if (result.Errors.Count() > 0)
                    {
                        // TempData["RegistrationError"] = "We Found you email in out system. Please try to login using your email and password.";
                    }
                    else
                    {
                        var accountBL = ServiceLocator.Current.GetInstance <IAccountBL>();

                        string emailCode = await _CustomUserManager.GenerateEmailConfirmationTokenAsync(customUser.Id);

                        string phoneCode = await CustomUser.GenerateTwoFactorTokenAsync(customUser.Id, "Phone Code");

                        await accountBL.SaveMobileGeneratedVerificationCode(customUser.ID, Convert.ToInt32(phoneCode));

                        // var accountBL = ServiceLocator.Current.GetInstance<IAccountBL>();
                        EmailTemplate emailTemplate = accountBL.GetEmail("EMAIL_VERIFICATION");

                        var    callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = customUser.Id, code = emailCode }, protocol: Request.Url.Scheme);
                        string emailBody   = String.Format(emailTemplate.Body, model.FirstName, callbackUrl);
                        await _CustomUserManager.SendEmailAsync(customUser.Id, emailTemplate.Subject, emailBody);

                        //await _CustomUserManager.SendSmsAsync(customUser.Id, "");

                        return(View(Mvc.Account.Views.DisplayEmail));
                    }

                    TempData["Errors"] = result.Errors;
                }
            }


            return(RedirectToAction(Mvc.Home.Index()));
        }
        public async virtual Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            // var token = await CustomUser.GenerateTwoFactorTokenAsync("1024", "Phone Code");


            // ClaimsIdentity identity = new ClaimsIdentity(DefaultAuthenticationTypes.TwoFactorCookie);
            // identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, "1020"));
            // AuthenticationManager.SignIn(identity);

            //return RedirectToAction(Mvc.Account.VerifyCode("EmailTokenProvider", Url.Action(Mvc.Customers.Customer.Default()), false));

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true

            var user = await CustomUser.FindByNameAsync(model.Email.ToLower().Trim());

            if (user == null)
            {
                ModelState.AddModelError("", "Invalid login attempt.");
                return(View(model));
            }
            if (!await CustomUser.IsEmailConfirmedAsync(user.Id))
            {
                ModelState.AddModelError("", "You need to confirm your email.");
                return(View(model));
            }

            var result = await CustomSignIn.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : false);

            switch (result)
            {
            case SignInStatus.Success:
                return(RedirectToLocal(returnUrl));

            case SignInStatus.LockedOut:
                return(View("Lockout"));

            case SignInStatus.RequiresVerification:
                return(RedirectToAction(Mvc.Account.VerifyCode("Phone Code", Url.Action(Mvc.Home.Index()), false)));

            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", "Invalid login attempt.");
                return(View(model));
            }
        }
        public virtual async Task <ActionResult> ResetPassword(ResetPasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var user = await CustomUser.FindByNameAsync(model.Email);

            if (user == null)
            {
                // Don't reveal that the user does not exist
                return(RedirectToAction("ResetPasswordConfirmation", "Account"));
            }
            var result = await CustomUser.ResetPasswordAsync(user.Id, model.Code, model.Password);

            if (result.Succeeded)
            {
                return(RedirectToAction("ResetPasswordConfirmation", "Account"));
            }
            AddErrors(result);
            return(View());
        }