public async Task Given_an_ApplicationUserStore_when_a_user_is_created_then_it_can_be_retrieved_by_userid()
        {
            // GIVEN a user store and user
            var userStore = new ApplicationUserStore(_authContext.Object);

            var user = new ApplicationUser
            {
                Id       = "TestUser3",
                UserName = "******",
                Email    = "*****@*****.**"
            };

            // WHEN the user is created
            await userStore.CreateAsync(user, false);

            // THEN the user should retrieved from the user store and match the original user
            var userFromStore = await userStore.FindByIdAsync(user.Id, false);

            userFromStore.Id.Should().Be(user.Id, "because the user has been created in and retrieved from the ApplicationUserStore.");
        }
예제 #2
0
        public async Task<ApplicationUser> Authorize(string token)
        {
            var fbClient = new FacebookClient(token);
            dynamic me = await fbClient.GetTaskAsync("me");

            var adminEmail = CloudConfigurationManager.GetSetting("email");

            try
            {
                var userStore = new ApplicationUserStore();

                var user = await userStore.FindByIdAsync(me.id);
                if (user == null)
                {
                    var newUser = new ApplicationUser()
                                      {
                                          Email = me.email,
                                          Id = me.id,
                                          UserName = me.email,
                                          Role = adminEmail == me.email ? "Admin" : "User",
                                          FirstName = me.first_name,
                                          LastName = me.last_name
                                      };

                    await userStore.CreateAsync(newUser);

                    return newUser;
                }

                return user;
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return null;
            }
        }
예제 #3
0
 public async Task <ApplicationUser> GetUserByIdAsync(int id)
 {
     return(await _store.FindByIdAsync(id));
 }