public async Task <IActionResult> Post(string email, string password, [FromBody] PatientSignUpViewModel value)
        {
            var doctor = await repo.GetDoctorByUserNameAsync(email);

            if (doctor == null)
            {
                return(StatusCode(403, "User doesn't exist"));
            }
            var result = await this.signInMgr.PasswordSignInAsync(doctor, password, false, false);

            if (!result.Succeeded)
            {
                return(StatusCode(403, "Incorrect password"));
            }

            var patient = new Patient()
            {
                UserName  = value.Email,
                Email     = value.Email,
                Age       = value.Age,
                Chamber   = value.Chamber,
                Diagnosis = value.Diagnosis,
                DoctorId  = doctor.Id,
                Doctor    = doctor,
                FirstName = value.FirstName,
                LastName  = value.LastName
            };

            await userMgr.CreateAsync(patient, value.Password);

            await userMgr.AddToRoleAsync(patient, "Patient");

            return(StatusCode(200, "Success"));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> SignUp(PatientSignUpViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var doctor = await doctorRepo.GetDoctorByUserNameAsync(User.Identity.Name);

                var patient = new Patient()
                {
                    UserName  = vm.Email,
                    Email     = vm.Email,
                    Age       = vm.Age,
                    Chamber   = vm.Chamber,
                    Diagnosis = vm.Diagnosis,
                    DoctorId  = doctor.Id,
                    Doctor    = doctor,
                    FirstName = vm.FirstName,
                    LastName  = vm.LastName
                };

                var result = await userMgr.CreateAsync(patient, vm.Password);

                await userMgr.AddToRoleAsync(patient, "Patient");

                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                return(View(vm));
            }
        }
Exemplo n.º 3
0
        public IActionResult PatientSignUp(PatientSignUpViewModel patientSignUpViewModel)
        {
            // Description: Registers a patient up for a MedNet account
            ViewBag.DoctorName = HttpContext.Session.GetString(Globals.currentUserName);
            string signPrivateKey = null, agreePrivateKey = null, signPublicKey = null, agreePublicKey = null;
            Assets <PatientCredAssetData> userAsset = _bigChainDbService.GetPatientAssetFromID(patientSignUpViewModel.PHN);

            // Check if PHN is already in use
            if (userAsset != null)
            {
                ModelState.AddModelError("", "A Patient profile with that PHN already exists");
                return(View(patientSignUpViewModel));
            }

            // Register fingerprint information
            int           numScans = 5;
            List <Image>  fpList   = FingerprintService.authenticateFP("24.84.225.22", numScans);
            List <byte[]> fpdb     = new List <byte[]>();

            if (fpList.Count > numScans)
            {
                ModelState.AddModelError("", "Something went wrong with the fingerprint scan, try again.");
                return(View(patientSignUpViewModel));
            }

            // Parse the input data for user registration
            var passphrase = patientSignUpViewModel.KeyWord;
            var password   = patientSignUpViewModel.Password;

            // Encrypt fingerprint data
            List <string> encrList = new List <string>();

            foreach (var fp in fpList)
            {
                byte[] fpByte  = FingerprintService.imgToByte(fp);
                string encrStr = EncryptionService.encryptFingerprintData(patientSignUpViewModel.PHN, passphrase, fpByte);
                encrList.Add(encrStr);
            }

            // Create a user for the Blockchain
            EncryptionService.getNewBlockchainUser(out signPrivateKey, out signPublicKey, out agreePrivateKey, out agreePublicKey);

            // Create the user Asset
            var userAssetData = new PatientCredAssetData
            {
                ID              = patientSignUpViewModel.PHN,
                DateOfBirth     = patientSignUpViewModel.DateOfBirth,
                PrivateKeys     = EncryptionService.encryptPrivateKeys(patientSignUpViewModel.PHN, passphrase, signPrivateKey, agreePrivateKey),
                DateOfRecord    = DateTime.Now,
                SignPublicKey   = signPublicKey,
                AgreePublicKey  = agreePublicKey,
                FingerprintData = encrList,
            };

            // Encrypt the user's password in the metadata
            var userMetadata = new PatientCredMetadata
            {
                FirstName      = patientSignUpViewModel.FirstName,
                LastName       = patientSignUpViewModel.LastName,
                Email          = patientSignUpViewModel.Email,
                hashedPassword = EncryptionService.hashPassword(password)
            };

            // Save the user Asset and Metadata
            var asset = new AssetSaved <PatientCredAssetData>
            {
                Type     = AssetType.Patient,
                Data     = userAssetData,
                RandomId = _random.Next(0, 100000)
            };
            var metadata = new MetaDataSaved <PatientCredMetadata>
            {
                data = userMetadata
            };

            // Send the user's information to the Blockchain database
            _bigChainDbService.SendCreateTransactionToDataBase(asset, metadata, signPrivateKey);
            return(RedirectToAction("PatientLookUp"));
        }