コード例 #1
0
        public PersonalDataModel GetPayloadValidateJWTToken(string accessToken)
        {
            try
            {
                byte[] publicKey = Convert.FromBase64String(OAuthConf.OAUTH2_VERIFY_TOKEN_PUBLIC_KEY);

                string jsonPayload = new JwtBuilder()
                                     .WithAlgorithm(new RS256Algorithm(new X509Certificate2(publicKey)))
                                     .WithValidator(new JwtValidator(new JsonNetSerializer(), new UtcDateTimeProvider(), 5 * 60))
                                     .MustVerifySignature()
                                     .Decode(accessToken);

                System.Diagnostics.Debug.Print(jsonPayload);

                JObject obj = JObject.Parse(jsonPayload);

                PersonalDataModel personalDataModel = new PersonalDataModel();
                if (obj != null)
                {
                    personalDataModel = obj.ToObject <PersonalDataModel>(JsonSerializer);
                }

                personalDataModel.Access_token = accessToken;

                return(personalDataModel);
            }
            catch (Exception e)
            {
                LogUtils.LogException(LogSeverity.ERROR, e, $"{nameof(AuthenticationManager)}.{nameof(GetPayloadValidateJWTToken)} failed.");
                return(null);
            }
        }
コード例 #2
0
        public string PrintLastSymptomOnsetDate()
        {
            PersonalDataModel pd = AuthenticationState.PersonalData;

            return($"Last Symptom Onset Date: {QuestionnaireViewModel.DateLabel}, " +
                   $"Selection: {QuestionnaireViewModel.Selection}, " +
                   $"MiBaDate:{pd?.Covid19_smitte_start}, " +
                   $"Date used for risk calc:{pd?.FinalMiBaDate}");
        }
コード例 #3
0
        //PUT /api/PersonalData Update personal info
        public IRestResponse PutPersonalData(PersonalDataModel personalDataModel)
        {
            var request = new RestRequest(resource, Method.PUT);

            request.AddHeader("api-key", apiKey);
            request.AddJsonBody(personalDataModel);
            var response = client.Execute(request);

            return(response);
        }
コード例 #4
0
        public async Task <IActionResult> PersonalDataFormAction(PersonalDataModel model)
        {
            int size = 200;

            ImageCheckResult imgCheck = _moneyImageParser.CheckImage(model.Photo, size * 1000);

            if (imgCheck == ImageCheckResult.MaxSizeError)
            {
                ViewData["ImageError"] = $"Photo wasn't changed. Maximum image size is {size}kb.";
            }

            if (imgCheck == ImageCheckResult.IsNotJpeg)
            {
                ViewData["ImageError"] = "Photo wasn't changed. Only jpeg image format supported.";
            }

            if (imgCheck == ImageCheckResult.Success)
            {
                await _moneyImageParser.SaveUserImage(model.Photo, User.Identity.Name);
            }

            UserInfo uInfo = new UserInfo
            {
                Address    = model.Address,
                BirthYear  = model.BirthYear,
                BirthDay   = model.BirthDay,
                BirthMonth = model.BirthMonth,
                Email      = model.Email,
                FirstName  = model.FirstName,
                LastName   = model.LastName,
                Phone      = model.Phone,
                Gender     = model.Gender,
                Login      = model.Login
            };

            await _userInfoManager.SetUserInfoAsync(uInfo, User.Identity.Name);

            await _logManager.WriteAsync(uInfo.Login, $"User '{uInfo.Login}' edited his personal data.");

            if (uInfo.Login != User.Identity.Name)
            {
                string name = uInfo.Login;
                await _logManager.WriteAsync(name, $"User '{User.Identity.Name}' renamed himself into '{name}'.");

                await _authentication.SignOutAsync();

                await _logManager.WriteAsync(name, $"User '{name}' signed out.");

                return(RedirectToAction(nameof(AccountController.Login), "Account"));
            }

            model.BirthMonthStr = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(model.BirthMonth);
            return(View(nameof(MainController.PersonalData), model));
        }
コード例 #5
0
        public ActionResult Create([Bind(Include = "Id,Adress,PhoneNumber,DateOfBirth")] PersonalDataModel model)
        {
            if (ModelState.IsValid)
            {
                var personalData = new PersonalData(model.Id, model.Adress, model.PhoneNumber, model.DateOfBirth);
                service.CreatePersonalData(personalData);
                return(RedirectToAction("Index"));
            }

            ViewBag.Id = new SelectList(serviceEmployee.GetAllEmployees(), "Id", "FirstName", model.Id);
            return(View(model));
        }
コード例 #6
0
        public async Task <IActionResult> PersonalData()
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'."));
            }

            var model = new PersonalDataModel();

            return(View(model));
        }
コード例 #7
0
 public ActionResult Index(PersonalDataModel model)
 {
     try
     {
         Setup.Initialize();
         PersonalDataManager.Save(model);
     }
     catch
     {
         return(View());
     }
     return(RedirectToAction("Index", "Home"));
 }
コード例 #8
0
        public async Task <IActionResult> ChangePasswordFormAction(PersonalDataModel model)
        {
            UserInfo uInfo = await _userInfoManager.GetUserInfoAsync(User.Identity.Name);

            model.Address       = uInfo.Address;
            model.BirthDay      = uInfo.BirthDay;
            model.BirthMonth    = uInfo.BirthMonth;
            model.BirthMonthStr = uInfo.BirthMonthStr;
            model.BirthYear     = uInfo.BirthYear;
            model.Email         = uInfo.Email;
            model.FirstName     = uInfo.FirstName;
            model.Gender        = uInfo.Gender;
            model.LastName      = uInfo.LastName;
            model.Login         = uInfo.Login;
            model.Phone         = uInfo.Phone;

            if (!await _moneyUserManager.IsNotOAuth(User.Identity.Name))
            {
                ViewData["PassChangeClass"]   = "text-danger";
                ViewData["PassChangeMessage"] = "Password change failed: authentication type error.";
                return(View(nameof(MainController.PersonalData), model));
            }

            if (!await _authentication.CheckPasswordAsync(model.ChangePassword.CurrentPassword, User.Identity.Name))
            {
                ViewData["PassChangeClass"]   = "text-danger";
                ViewData["PassChangeMessage"] = "Password change failed: wrong current password.";
                return(View(nameof(MainController.PersonalData), model));
            }

            IdentityResult result = await _moneyUserManager.ChangePasswordAsync(model.ChangePassword.CurrentPassword, model.ChangePassword.Password, User.Identity.Name);

            if (!result.Succeeded)
            {
                ViewData["PassChangeClass"]   = "text-danger";
                ViewData["PassChangeMessage"] = "Password change failed.";
                return(View(nameof(MainController.PersonalData), model));
            }

            await _logManager.WriteAsync(User.Identity.Name, $"User '{User.Identity.Name}' changed his password.");

            ViewData["PassChangeClass"]   = "text-success";
            ViewData["PassChangeMessage"] = "Password successfully changed.";
            return(View(nameof(MainController.PersonalData), model));
        }
コード例 #9
0
        public async Task <IActionResult> PersonalData(PersonalDataModel model)
        {
            UserInfo uInfo = await _userInfoManager.GetUserInfoAsync(User.Identity.Name);

            model.Address       = uInfo.Address;
            model.BirthDay      = uInfo.BirthDay;
            model.BirthMonth    = uInfo.BirthMonth;
            model.BirthMonthStr = uInfo.BirthMonthStr;
            model.BirthYear     = uInfo.BirthYear;
            model.Email         = uInfo.Email;
            model.FirstName     = uInfo.FirstName;
            model.Gender        = uInfo.Gender;
            model.LastName      = uInfo.LastName;
            model.Login         = uInfo.Login;
            model.Phone         = uInfo.Phone;

            return(View(model));
        }
コード例 #10
0
        // GET: PersonalData/Edit/5
        public ActionResult Edit(long id)
        {
            var personalData = service.GetPersonalData(id);

            if (personalData == null)
            {
                return(HttpNotFound());
            }
            var personalDataModel = new PersonalDataModel
            {
                Id          = personalData.Id,
                Adress      = personalData.Adress,
                PhoneNumber = personalData.PhoneNumber,
                DateOfBirth = personalData.DateOfBirth
            };

            ViewBag.Id = new SelectList(serviceEmployee.GetAllEmployees(), "Id", "FirstName", personalData.Id);
            return(View(personalDataModel));
        }
コード例 #11
0
        void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e)
        {
            string errorMsgPrefix = $"{nameof(InformationAndConsentViewModel)}.{nameof(OnAuthCompleted)}: ";

            System.Diagnostics.Debug.Print("Authenticated: " + e.IsAuthenticated);
            if ((e?.IsAuthenticated ?? false) && e.Account?.Properties != null && e.Account.Properties.ContainsKey("access_token"))
            {
                LogUtils.LogMessage(Enums.LogSeverity.INFO, errorMsgPrefix + "User returned from ID Porten after authentication and access_token exists.");

                //Access_token
                string            token   = e.Account?.Properties["access_token"];
                PersonalDataModel payload = _authManager.GetPayloadValidateJWTToken(token);

                if (payload == null)
                {
                    OnError?.Invoke(this, AuthErrorType.Unknown);
                }
                else
                {
                    //Expiration time
                    if (e.Account.Properties.TryGetValue("expires_in", out string expires))
                    {
                        int.TryParse(expires, out int expiresSeconds);
                        if (expiresSeconds > 0)
                        {
                            payload.TokenExpiration = DateTime.Now.AddSeconds(expiresSeconds);
                            LogUtils.LogMessage(LogSeverity.INFO, $"{errorMsgPrefix} Access-token expires timestamp is {payload.TokenExpiration?.ToString(CultureInfo.InvariantCulture)}");
                        }
                    }
                    else
                    {
                        LogUtils.LogMessage(LogSeverity.ERROR, errorMsgPrefix + "'expires_in' value does not exist");
                    }

                    SaveCovidRelatedAttributes(payload);

                    if (AuthenticationState.PersonalData.IsBlocked)
                    {
                        OnError?.Invoke(this, AuthErrorType.MaxTriesExceeded);
                    }
                    else
                    {
                        if (AuthenticationState.PersonalData.IsNotInfected)
                        {
                            OnError?.Invoke(this, AuthErrorType.NotInfected);
                        }
                        else
                        {
                            if (!payload.Validate() || AuthenticationState.PersonalData.UnknownStatus)
                            {
                                if (AuthenticationState.PersonalData.UnknownStatus)
                                {
                                    LogUtils.LogMessage(LogSeverity.ERROR, errorMsgPrefix + "Value Covid19_status = ukendt");
                                }
                                OnError?.Invoke(this, AuthErrorType.Unknown);
                            }
                            else
                            {
                                OnSuccess?.Invoke(this, null);
                            }
                        }
                    }
                }
            }
            else
            {
                //The user clicked back
                Restart();
            }
        }
コード例 #12
0
 void SaveCovidRelatedAttributes(PersonalDataModel payload)
 {
     AuthenticationState.PersonalData = payload;
 }
コード例 #13
0
 public static void Save(PersonalDataModel dragon)
 {
     DbContext.Current.Add(dragon);
 }
コード例 #14
0
 //PUT /api/PersonalData Update personal info
 public IResponse PutPersonalData(PersonalDataModel personalDataModel)
 {
     return(Request.Put(resource).WithHeaders("api-key", apiKey).AddJsonBody(personalDataModel).Build().Execute());
 }