Exemple #1
0
        // GET: Patient
        public ActionResult Login()
        {
            Session.Clear();
            PatientLoginViewModel obj = new PatientLoginViewModel();

            return(View(obj));
        }
        public IActionResult Login(PatientLoginViewModel indexViewModel)
        {
            ViewBag.UserName = HttpContext.Session.GetString(Globals.currentUserName);
            if (!ModelState.IsValid)
            {
                return(View(indexViewModel));
            }
            string signPrivateKey = null, agreePrivateKey = null;
            Assets <PatientCredAssetData> userAsset = _bigChainDbService.GetPatientAssetFromID(indexViewModel.PatientPHN);

            if (userAsset == null)
            {
                ModelState.AddModelError("", "We could not find a matching user");
                return(View(indexViewModel));
            }
            var hashedKeys = userAsset.data.Data.PrivateKeys;

            try
            {
                EncryptionService.getPrivateKeyFromIDKeyword(indexViewModel.PatientPHN, indexViewModel.PatientKeyword, hashedKeys, out signPrivateKey, out agreePrivateKey);
            }
            catch
            {
                ModelState.AddModelError("", "Keyword may be incorrect");
                return(View(indexViewModel));
            }
            PatientCredMetadata userMetadata = _bigChainDbService.GetMetadataFromAssetPublicKey <PatientCredMetadata>(userAsset.id, userAsset.data.Data.SignPublicKey);
            var password = indexViewModel.password;

            if (EncryptionService.verifyPassword(password, userMetadata.hashedPassword))
            {
                HttpContext.Session.SetString(Globals.currentPSPriK, signPrivateKey);
                HttpContext.Session.SetString(Globals.currentPAPriK, agreePrivateKey);
                HttpContext.Session.SetString(Globals.currentPSPubK, userAsset.data.Data.SignPublicKey);
                HttpContext.Session.SetString(Globals.currentPAPubK, userAsset.data.Data.AgreePublicKey);
                HttpContext.Session.SetString(Globals.currentUserName, $"{userMetadata.FirstName} {userMetadata.LastName}");
                HttpContext.Session.SetString(Globals.currentUserID, userAsset.data.Data.ID);
                return(RedirectToAction("PatientOverview"));
            }
            else
            {
                ModelState.AddModelError("", "Password or Keyword incorrect.");
                return(View(indexViewModel));
            }
        }
Exemple #3
0
        public ActionResult Login(PatientLoginViewModel obj)
        {
            obj.dateTime = DateTime.Now;

            if (obj.OTP != null)
            {
                ReturnObject ro = new AppointmentAPIController().VerifyMobile(obj.MobileNo, obj.OTP);

                if (ro.status_code == 1)
                {
                    using (var db = new ddiarydbEntities())
                    {
                        var patient = db.Patient_Master.Where(x => x.Patient_contact == obj.MobileNo).FirstOrDefault();

                        if (patient != null)
                        {
                            Session["UserID"]   = new EncryptDecrypt().Encrypt(patient.Patient_Id.ToString());;
                            Session["UserName"] = patient.Patient_name.ToString();
                        }
                        else
                        {
                            Session["UserMobile"] = obj.MobileNo;
                        }
                    }

                    return(RedirectToAction("Details"));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Please Enter a valid OTP.");
                }
            }
            else
            {
                ModelState.AddModelError(string.Empty, "Please Enter a OTP.");
            }

            return(View(obj));
        }