Exemple #1
0
        public async Task <IHttpActionResult> Register(ANDROIDGebruiker model)
        {
            var user = new User
            {
                UserName          = model.Name,
                Email             = model.Email,
                Created           = DateTime.Now,
                profilePublic     = true,
                FirstName         = model.FirstName,
                LastName          = model.LastName,
                Birthday          = model.Birthday,
                Zipcode           = model.Zipcode,
                LockoutEnabled    = false,
                EmailConfirmed    = true,
                AccessFailedCount = 0
            };
            var result = await UserManager.CreateAsync(user, model.Password);

            if (result.Succeeded)
            {
                var role = RoleManager.FindByName("Gebruiker");

                if (user != null)
                {
                    UserManager.AddToRole(user.Id, role.Name);
                }
            }

            return(Ok(model));
        }
Exemple #2
0
        public async Task <IHttpActionResult> Login(ANDROIDLoginView model)
        {
            ANDROIDGebruiker us = null;
            // Require the user to have a confirmed email before they can log on.
            var user = await UserManager.FindByNameAsync(model.Name);

            if (user == null)
            {
                return(Ok(us));
            }
            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            var result = await SignInManager.PasswordSignInAsync(model.Name, model.Password, false, shouldLockout : true);

            switch (result)
            {
            case SignInStatus.Success:
                user.LastLogin = DateTime.Now;
                var store = new UserStore <User>(new ApplicationDbContext());
                UserManager.Update(user);
                var ctx = store.Context;

                ctx.SaveChanges();
                ANDROIDGebruiker gebruiker = new ANDROIDGebruiker()
                {
                    Name      = user.UserName,
                    FirstName = user.FirstName,
                    LastName  = user.LastName,
                    Birthday  = user.Birthday,
                    Zipcode   = user.Zipcode,
                    Email     = user.Email
                };

                return(Ok(gebruiker));

            case SignInStatus.Failure:
                return(Ok(us));

            default:
                return(Ok(us));
            }
        }