Example #1
0
        public async Task <ActionResult> DoctorLogin(LoginRegisterViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var result = await SignInManager.PasswordSignInAsync(model.LoginViewModel.Email, model.LoginViewModel.Password, model.LoginViewModel.RememberMe, shouldLockout : false);

            switch (result)
            {
            case SignInStatus.Success:
            {
                //var userId = HttpContext.User.Identity.GetUserId();
                string userId = UserManager.FindByName(model.LoginViewModel.Email)?.Id;
                SessionHandler.UserName = model.LoginViewModel.Email;
                SessionHandler.Password = model.LoginViewModel.Password;
                SessionHandler.UserId   = userId;
                var objRepo = new DoctorRepository();
                var doctor  = objRepo.GetByUserId(userId);
                if (doctor == null)
                {
                    ModelState.AddModelError("", "Invalid login attempt.");
                    ViewBag.ModelError = "Invalid Username or Password.";
                    return(View(model));
                }
                if (doctor.status == null || !((bool)doctor.status))
                {
                    ModelState.AddModelError("", "Account review is in progress. You can login after approval.");
                    ViewBag.ModelError = "Account review is in progress. You can login after approval.";
                    return(View(model));
                }

                var userModel = new UserInfoModel();
                userModel.Id                = doctor.doctorID;
                userModel.Email             = doctor.email;
                userModel.FirstName         = doctor.firstName;
                userModel.LastName          = doctor.lastName;
                userModel.userId            = doctor.userId;
                userModel.title             = doctor.title;
                userModel.timeZone          = doctor.timeZone;
                userModel.timeZoneOffset    = doctor.timeZoneoffset;
                userModel.role              = doctor.role;
                userModel.iOSToken          = doctor.iOSToken;
                userModel.AndroidToken      = doctor.AndroidToken;
                SessionHandler.UserInfo     = userModel;
                SessionHandler.ProfilePhoto = doctor.doctorID.ToString() + ".png";


                if (doctor.active == null || (bool)doctor.active)
                {
                    //return RedirectToAction("DoctorTimings", "Doctor");
                    return(RedirectToAction("Index", "DoctorAppointment"));
                }
            }
                return(RedirectToLocal(returnUrl));

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

            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", "Invalid Username or Password.");
                ViewBag.ModelError = "Invalid Username or Password.";
                return(View(model));
            }
        }
Example #2
0
        public async Task <ActionResult> Questions(string email, string code)
        {
            var user = await UserManager.FindByNameAsync(email);

            ForgotPasswordCodeModel.Token = code;


            var objModel = new SecretQuestionModel();

            objModel.Email = user.UserName;
            var    roles      = UserManager.GetRoles(user.Id);
            Random rnd        = new Random();
            int    caseSwitch = rnd.Next(1, 4);

            if (roles.Contains("Patient"))
            {
                PatientRepository objRepo = new PatientRepository();
                var resultAdd             = objRepo.GetByUserId(user.Id);
                switch (caseSwitch)
                {
                case 1:
                    objModel.SecretQuestion     = resultAdd.secretQuestion1;
                    objModel.SecretAnswerHidden = resultAdd.secretAnswer1;
                    break;

                case 2:
                    objModel.SecretQuestion     = resultAdd.secretQuestion2;
                    objModel.SecretAnswerHidden = resultAdd.secretAnswer2;
                    break;

                default:

                    objModel.SecretQuestion     = resultAdd.secretQuestion3;
                    objModel.SecretAnswerHidden = resultAdd.secretAnswer3;
                    break;
                }
                if (objModel.SecretQuestion == null)
                {
                    if (resultAdd.secretQuestion1 != null)
                    {
                        objModel.SecretQuestion     = resultAdd.secretQuestion1;
                        objModel.SecretAnswerHidden = resultAdd.secretAnswer1;
                    }
                    if (resultAdd.secretQuestion2 != null)
                    {
                        objModel.SecretQuestion     = resultAdd.secretQuestion2;
                        objModel.SecretAnswerHidden = resultAdd.secretAnswer2;
                    }
                    if (resultAdd.secretQuestion3 != null)
                    {
                        objModel.SecretQuestion     = resultAdd.secretQuestion3;
                        objModel.SecretAnswerHidden = resultAdd.secretAnswer3;
                    }
                }
            }
            else if (roles.Contains("Doctor"))
            {
                DoctorRepository objRepo = new DoctorRepository();
                var resultAdd            = objRepo.GetByUserId(user.Id);
                switch (caseSwitch)
                {
                case 1:
                    objModel.SecretQuestion     = resultAdd.secretQuestion1;
                    objModel.SecretAnswerHidden = resultAdd.secretAnswer1;
                    break;

                case 2:
                    objModel.SecretQuestion     = resultAdd.secretQuestion2;
                    objModel.SecretAnswerHidden = resultAdd.secretAnswer2;
                    break;

                default:
                    objModel.SecretQuestion     = resultAdd.secretQuestion3;
                    objModel.SecretAnswerHidden = resultAdd.secretAnswer3;
                    break;
                }
                if (objModel.SecretQuestion == null)
                {
                    if (resultAdd.secretQuestion1 != null)
                    {
                        objModel.SecretQuestion     = resultAdd.secretQuestion1;
                        objModel.SecretAnswerHidden = resultAdd.secretAnswer1;
                    }
                    if (resultAdd.secretQuestion2 != null)
                    {
                        objModel.SecretQuestion     = resultAdd.secretQuestion2;
                        objModel.SecretAnswerHidden = resultAdd.secretAnswer2;
                    }
                    if (resultAdd.secretQuestion3 != null)
                    {
                        objModel.SecretQuestion     = resultAdd.secretQuestion3;
                        objModel.SecretAnswerHidden = resultAdd.secretAnswer3;
                    }
                }
            }

            if (objModel.SecretQuestion == null)
            {
                ViewBag.ErrorMessage = "Sorry! User does not setup his recovery secret questions.";
            }
            return(View("ForgotPasswordConfirmation", objModel));
        }
Example #3
0
        public async Task <ActionResult> Login(LoginRegisterViewModel model, string returnUrl)
        {
            //var IsPatient = (bool)ViewBag.IsPatient;


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

            //var strContent = JsonConvert.SerializeObject(model);
            //var response = ApiConsumerHelper.PostData("api/Account/Login", strContent);
            //var resultTest = JsonConvert.DeserializeObject<SignInStatus>(response);

            // This doen't count login failures towards lockout only two factor authentication
            // To enable password failures to trigger lockout, change to shouldLockout: true
            var result = await SignInManager.PasswordSignInAsync(model.LoginViewModel.Email, model.LoginViewModel.Password, model.LoginViewModel.RememberMe, shouldLockout : false);

            switch (result)
            {
            case SignInStatus.Success:
            {
                //var userId = HttpContext.User.Identity.GetUserId();
                string userId = UserManager.FindByName(model.LoginViewModel.Email)?.Id;
                SessionHandler.UserName = model.LoginViewModel.Email;
                SessionHandler.Password = model.LoginViewModel.Password;
                SessionHandler.UserId   = userId;

                var roles = UserManager.GetRoles(userId);
                if (roles.Contains("Doctor"))
                {
                    var objRepo   = new DoctorRepository();
                    var doctor    = objRepo.GetByUserId(userId);
                    var userModel = new UserInfoModel();
                    userModel.Id             = doctor.doctorID;
                    userModel.Email          = doctor.email;
                    userModel.FirstName      = doctor.firstName;
                    userModel.LastName       = doctor.lastName;
                    userModel.userId         = doctor.userId;
                    userModel.title          = doctor.title;
                    userModel.timeZoneOffset = doctor.timeZoneoffset;
                    userModel.role           = doctor.role;
                    userModel.iOSToken       = doctor.iOSToken;
                    userModel.AndroidToken   = doctor.AndroidToken;
                    SessionHandler.UserInfo  = userModel;

                    if (doctor.picture != null && doctor.picture.Count() > 0)
                    {
                        SessionHandler.ProfilePhoto = Encoding.ASCII.GetString(doctor.picture);
                    }

                    if (doctor.active == null || (bool)doctor.active)
                    {
                        return(RedirectToAction("DoctorTimings", "Doctor"));
                    }
                }
                else if (roles.Contains("Patient"))
                {
                    var objRepo   = new PatientRepository();
                    var patient   = objRepo.GetByUserId(userId);
                    var userModel = new UserInfoModel();
                    userModel.Id             = patient.patientID;
                    userModel.Email          = patient.email;
                    userModel.FirstName      = patient.firstName;
                    userModel.LastName       = patient.lastName;
                    userModel.userId         = patient.userId;
                    userModel.title          = patient.title;
                    userModel.timeZoneOffset = patient.timeZoneoffset;
                    userModel.role           = patient.role;
                    userModel.iOSToken       = patient.iOSToken;
                    userModel.AndroidToken   = patient.AndroidToken;
                    SessionHandler.UserInfo  = userModel;

                    if (patient.active == null || (bool)patient.active)
                    {
                        return(RedirectToAction("Index", "Patient"));
                    }
                }
                else if (roles.Contains("Admin"))
                {
                    var user = await UserManager.FindAsync(model.LoginViewModel.Email, model.LoginViewModel.Password);

                    Session["LogedUserID"]       = model.LoginViewModel.Email;
                    Session["LogedUserFullname"] = user.FirstName + " " + user.LastName;
                    return(RedirectToAction("Default", "Admin"));
                }
            }
                return(RedirectToLocal(returnUrl));

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

            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", "Invalid login attempt.");
                return(View(model));
            }
        }