コード例 #1
0
        public async Task<IHttpActionResult> RegisterExternal(RegisterExternalBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var info = await Authentication.GetExternalLoginInfoAsync();
            if (info == null)
            {
                return InternalServerError();
            }

            var user = new ApplicationUser() { UserName = model.Username, Email = model.Email };

            IdentityResult result = await UserManager.CreateAsync(user);
            if (!result.Succeeded)
            {
                return GetErrorResult(result);
            }

            result = await UserManager.AddLoginAsync(user.Id, info.Login);
            if (!result.Succeeded)
            {
                return GetErrorResult(result); 
            }
            return Ok();
        }
コード例 #2
0
        private void SetupUsers()
        {
            var firstUser = new ApplicationUser()
            {
                UserName = "******",
                Id = "1",
                Posts = new List<Post>()
                {
                    new Post()
                    {
                        Id = 1,
                        Author = new ApplicationUser() {UserName = "******", Id = "1"},
                        Comment = "First",
                        Title = "First Title",
                        Replies = new List<Reply>()
                        {
                            new Reply()
                            {
                                Id = 1,
                                Author = new ApplicationUser() {UserName = "******", Id = "2"},
                                Comment = "First reply",
                                Post = new Post(){Id=1}
                            }
                        }
                    },
                    new Post()
                    {
                        Id = 2,
                        Author = new ApplicationUser() {UserName = "******", Id = "1"},
                        Comment = "Second",
                        Title = "Second Title",
                        Replies = new List<Reply>()
                    },
                    new Post()
                    {
                        Id = 3,
                        Author = new ApplicationUser() {UserName = "******", Id = "1"},
                        Comment = "Third",
                        Title = "Third Title",
                        Replies = new List<Reply>()
                    }
                },
                Following = new List<ApplicationUser>()
                {
                    new ApplicationUser()
                    {
                        UserName = "******",
                        Id = "1234",
                        Posts = new List<Post>()
                        {
                            new Post()
                            {
                                Id = 20,
                                Author = new ApplicationUser() {UserName = "******", Id = "11"},
                                Comment = "Second1",
                                Title = "Second Title1",
                                Replies = new List<Reply>()
                            },
                            new Post()
                            {
                                Id = 21,
                                Author = new ApplicationUser() {UserName = "******", Id = "12"},
                                Comment = "Second2",
                                Title = "Second Title2",
                                Replies = new List<Reply>()
                            }
                        }
                    }
                }
            };
            var fakeUsers = new List<ApplicationUser>()
            {
                firstUser
            };

            this.UsersRepositoryMock.Setup(p => p.All()).Returns(fakeUsers.AsQueryable());
            this.UsersRepositoryMock.Setup(p => p.GetById(It.IsAny<string>()))
                .Returns(firstUser);
        }
コード例 #3
0
        public async Task<IHttpActionResult> Register(RegisterBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var user = new ApplicationUser() { UserName = model.Username, Email = model.Email };

            IdentityResult result = await UserManager.CreateAsync(user, model.Password);

            if (!result.Succeeded)
            {
                return GetErrorResult(result);
            }
           
            return Ok();
        }