Ejemplo n.º 1
0
        public ActionResult Register(RegisterUserViewModel model)
        {
            // MVC check to make sure all inputed values adhear to the view model's validation attributes.
            if (ModelState.IsValid)
            {
                // check for the user in the repository, if it is there assign that user.
                var user = xboxUserService.GetXboxUser(model.Gamertag);

                // TODO: If it is not in our DB, make a call to xboxapi and is found insert into into our DB and assign the new user.
                // if (user == null) { // check api and assign to user }

                // Good, the gamertag is actually valid - now lets use it to setup a user account.
                if (user != null)
                {
                    var newUser = new User()
                    {
                        Name = model.Name,
                        Email = model.Email,
                        Password = model.Password,
                        XboxUser = user,
                        XboxUserID = user.XboxUserID
                    };

                    userService.CreateUser(newUser);
                    userService.SaveUser();

                    var ident = new ClaimsIdentity(
                      new[] { 
                        // adding following 2 claim just for supporting default antiforgery provider
                        new Claim(ClaimTypes.NameIdentifier,  model.Name),
                        new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", "ASP.NET Identity", "http://www.w3.org/2001/XMLSchema#string"),
                        new Claim(ClaimTypes.Name, model.Name)
                        },
                        DefaultAuthenticationTypes.ApplicationCookie);

                    HttpContext.GetOwinContext().Authentication.SignIn(new AuthenticationProperties { IsPersistent = true }, ident);
                    return RedirectToAction("Index", "Feed");
                }
                else
                {
                    // If no user was found in neither our repository or on the xboxpi, then it probably doesn't exist so alert the user.
                    ModelState.AddModelError("Gamertag", "Gamertag not found.");
                }
            }

            return View(model);
        }
Ejemplo n.º 2
0
 public void CreateUser(User User)
 {
     UsersRepository.Add(User);
 }