public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            if (SocialSecurityNumber != "0000080348")
            {
                ModelState.AddModelError(nameof(SocialSecurityNumber), "Diese SVNr ist unbekannt!");
                return(Page());
            }

            //analog für HandyNr

            VerificationToken verificationToken = VerificationToken.NewToken();

            await _unitOfWork.VerificationTokens.AddAsync(verificationToken);

            await _unitOfWork.SaveChangesAsync();

            _smsService.SendSms(Mobilnumber, "CoronaTest - Token: {verificationToken.token}!");

            return(RedirectToPage("/Security/Verification", new { verificationIdentifier = verificationToken.Identifier }));
        }
예제 #2
0
        ///<Summary>
        /// OnPost
        ///</Summary>
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var participant = await _unitOfWork.ParticipantRepository.GetByParticipantBySocialSecurityNumberAndMobileNumberAsync(SocialSecurityNumber);

            if (SocialSecurityNumber != participant?.SocialSecurityNumber)
            {
                ModelState.AddModelError(nameof(SocialSecurityNumber), "Diese SVNr ist unbekannt!");

                return(Page());
            }
            if (Mobilenumber != participant?.Mobilenumber)
            {
                ModelState.AddModelError(nameof(Mobilenumber), "Diese Handynummer ist unbekannt!");
                return(Page());
            }


            VerificationToken verificationToken = VerificationToken.NewToken(participant);

            await _unitOfWork.VerificationTokens.AddAsync(verificationToken);

            await _unitOfWork.SaveChangesAsync();

            _smsService.SendSms(Mobilenumber, $"CoronaTest - Token: {verificationToken.Token} !");



            return(RedirectToPage("/Security/Verification", new { verificationIdentifier = verificationToken.Identifier }));
        }
        //public Participant participant = new Participant();


        public async Task <IActionResult> OnPost()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            /* if (!ValidationSVNR.CheckSsnr(Participant.SocialSecurityNumber))
             * {
             *   ModelState.AddModelError($"{nameof(Participant)}.{nameof(Participant.SocialSecurityNumber)}", $"Die SVNr {Participant.SocialSecurityNumber} ist ungültig");
             *   return Page();
             * }*/


            //  var p = GetParticipant();

            var p = Participant.GetNewModel();

            await _unitOfWork.ParticipantRepository.AddAsync(p);

            await _unitOfWork.SaveChangesAsync();

            /* try
             * {
             *   await _unitOfWork.SaveChangesAsync();
             *
             * }
             * catch(ValidationException ex)
             * {
             *   ModelState.AddModelError("", $"{ex.Message}");
             *   return Page();
             * }*/


            VerificationToken verificationToken = VerificationToken.NewToken(p);

            await _unitOfWork.VerificationTokens.AddAsync(verificationToken);

            await _unitOfWork.SaveChangesAsync();

            _smsService.SendSms(Participant.Mobilenumber, $"CoronaTest - Token: {verificationToken.Token} !");


            return(RedirectToPage("../Security/Verification", new { verificationIdentifier = verificationToken.Identifier }));//, new { verificationIdentifier = verificationToken.Identifier });
        }
예제 #4
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                Message = "Angaben sind nicht korrekt";
                return(Page());
            }

            if (!SsnValidation.IsValideSsn(SocialSecurityNumber))
            {
                ModelState.AddModelError(nameof(SocialSecurityNumber), "Diese SVNr ist unbekannt!");
                Message = "SVN Angabe ist nicht korrekt";
                return(Page());
            }

            /*
             *                              if (SocialSecurityNumber != "0000080384")
             *                              {
             *                                       ModelState.AddModelError(nameof(SocialSecurityNumber), "Diese SVNr ist unbekannt!");
             *                                       return Page();
             *                              }
             */
            // analog für HandyNr

            VerificationToken verificationToken = VerificationToken.NewToken();

            await _unitOfWork.VerificationTokens.AddAsync(verificationToken);

            await _unitOfWork.SaveChangesAsync();

            // _smsService.SendSms(Mobilenumber, $"CoronaTest - Token: {verificationToken.Token} !");
            // for testing purposes, comment out upper line
            Participant participant;

            try
            {
                participant = await _unitOfWork.Participants
                              .GetParticipantByPhoneAsync(Mobilenumber);

                if (participant == null)
                {
                    Message = "Teilnehmer nicht vorhanden";
                    return(Page());
                }
            }
            catch (Exception)
            {
                Message = "Datenbank fehlerhaft";
                return(Page());
            }
            // ----- set cookie using Microsoft.AspNetCore.Http --------------
            CookieOptions option = new CookieOptions
            {
                Path        = "/",
                HttpOnly    = false,
                IsEssential = true,
                Expires     = DateTime.Now.AddMinutes(15)
            };

            Response.Cookies.Append("MyCookieId", $"{participant.Id}", option);
            // ---------------------------------------------------------------
            return(RedirectToPage("/Security/Verification",
                                  new { verificationIdentifier = verificationToken.Identifier, participantId = participant.Id }));
        }