Beispiel #1
0
    private void DeserializeObject(string filename)
    {
        // Create a Type array.
        Type [] extraTypes = new Type[3];
        extraTypes[0] = typeof(Address);
        extraTypes[1] = typeof(Phone);
        extraTypes[2] = typeof(InternationalPhone);

        // Create the XmlSerializer instance.
        XmlSerializer mySerializer = new XmlSerializer
                                         (typeof(Teacher), extraTypes);

        // Reading a file requires a FileStream.
        FileStream fs      = new FileStream(filename, FileMode.Open);
        Teacher    teacher = (Teacher)mySerializer.Deserialize(fs);

        // Read the extra information.
        Address            a  = (Address)teacher.Info[0];
        Phone              p  = (Phone)teacher.Info[1];
        InternationalPhone Ip =
            (InternationalPhone)teacher.PhoneInfo;

        Console.WriteLine(teacher.Name);
        Console.WriteLine(a.City);
        Console.WriteLine(p.PhoneNumber);
        Console.WriteLine(Ip.CountryCode);
    }
        public async Task <IActionResult> OnPostAsync(string code)
        {
            ReturnUrl ??= "/Index";
            if (!TempData.TryGetValue("VerificationSecret", out object secretKey))
            {
                return(RedirectToPage("/User/Login", new { ReturnUrl }));
            }

            if (!TempData.TryGetValue("Phone", out object phone))
            {
                return(RedirectToPage("/User/Login", new { ReturnUrl }));
            }

            var internationalPhone = new InternationalPhone((string)phone);
            var info = new UserVerificationInfo(internationalPhone, (string)secretKey);

            if (!verificationService.CheckVerificationCode(info, code))
            {
                // Prevent deletion of secret if code was entered incorrectly.
                TempData.Keep();
                return(Page());
            }

            await identityService.SignInOrRegisterWithPhoneAsync(internationalPhone);

            return(LocalRedirect(ReturnUrl));
        }
Beispiel #3
0
        public async Task <IActionResult> OnPostAsync(string phone)
        {
            if (InternationalPhone.TryParse(phone, out InternationalPhone parsed))
            {
                UserVerificationInfo info = await verificationService.SendVerificationCodeAsync(parsed);

                TempData["VerificationSecret"] = info.SecretKey;
                TempData["Phone"] = info.Phone.Formatted;
                return(RedirectToPage("/User/Verify", new { ReturnUrl }));
            }

            return(Page());
        }
Beispiel #4
0
        public async Task SignInOrRegisterWithPhoneAsync(InternationalPhone phone)
        {
            ApplicationUser user = await userManager.Users.FirstOrDefaultAsync(u => u.PhoneNumber == phone.Formatted);

            if (user == null)
            {
                user = new ApplicationUser
                {
                    UserName    = StripSpecialCharacters(phone.Formatted),
                    PhoneNumber = phone.Formatted
                };
                var result = await userManager.CreateAsync(user);

                result = await userManager.AddToRoleAsync(user, Roles.User);
            }

            var identity = new ClaimsIdentity(AuthenticationSchemes.User);

            identity.AddClaim(new Claim(ClaimTypes.Role, Roles.User));
            identity.AddClaim(new Claim(ClaimTypes.Name, user.Id));
            var principal = new ClaimsPrincipal(identity);
            await httpContextAccessor.HttpContext.SignInAsync(AuthenticationSchemes.User, principal);
        }
Beispiel #5
0
 public UserVerificationInfo(InternationalPhone phone, string secretKey)
 {
     Phone     = phone;
     SecretKey = secretKey;
 }
 public Task SendAsync(InternationalPhone phone, string message)
 {
     return(MessageResource.CreateAsync(to: new Twilio.Types.PhoneNumber(phone.Formatted), from: new Twilio.Types.PhoneNumber("+16106157515"), body: message));
 }