Beispiel #1
0
        public async Task <UserReturnModel> Register([FromBody] UserRegisterModel formData)
        {
            if (ModelState.IsValid)
            {
                UserReturnModel user = _repo.Register(formData);
                if (user != null)
                {
                    ClaimsPrincipal principal = user.SetClaims();
                    await HttpContext.SignInAsync(principal);

                    return(user);
                }
            }
            return(null);
        }
        public async Task <UserReturnModel> Login([FromBody] LoginUserModel creds)
        {
            if (ModelState.IsValid)
            {
                UserReturnModel user = _db.Login(creds);
                if (user != null)
                {
                    ClaimsPrincipal principal = user.SetClaims();
                    await HttpContext.SignInAsync(principal);

                    return(user);
                }
            }
            return(null);
        }
        public async Task <UserReturnModel> Login([FromBody] UserLoginModel userData)
        {
            if (!ModelState.IsValid)
            {
                return(null);
            }
            try {
                UserReturnModel user      = _repo.Login(userData);
                var             principal = user.SetClaims();
                await HttpContext.SignInAsync(principal);

                return(user);
            } catch (Exception e) {
                System.Console.WriteLine(e.Message);
            }
        }
        public async Task <UserReturnModel> Register([FromBody] UserCreateModel userData)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    UserReturnModel user      = _repo.Register(userData);
                    ClaimsPrincipal principal = user.SetClaims();
                    await HttpContext.SignInAsync(principal);

                    return(user);
                }
                catch (Exception e)
                {
                    System.Console.WriteLine(e.Message);
                }
            }
            return(null);
        }
        public async Task <UserReturnModel> Register([FromBody] RegisterUserModel creds)
        {
            // Console.WriteLine("Here it should be");
            // Console.WriteLine(creds);

            if (ModelState.IsValid)
            {
                UserReturnModel user = _db.Register(creds);
                if (user != null)
                {
                    ClaimsPrincipal principal = user.SetClaims();
                    await HttpContext.SignInAsync(principal);

                    return(user);
                }
            }

            // Console.WriteLine("It didnt validate, better figure out why.");
            return(null);
        }
Beispiel #6
0
        public async Task <UserReturnModel> Login([FromBody] UserLoginModel formData)
        {
            if (formData == null)
            {
                throw new System.ArgumentNullException(nameof(formData));
            }

            if (ModelState.IsValid)
            {
                UserReturnModel user = _repo.Login(formData);
                if (user != null)
                {
                    ClaimsPrincipal principal = user.SetClaims();
                    await HttpContext.SignInAsync(principal);

                    return(user);
                }
            }
            return(null);
        }
Beispiel #7
0
        //tasks can do more than one thing, sends back via cookie, a header w/a token that
        //tells the front end to save the info/credentials.
        public async Task <UserReturnModel> Register([FromBody] UserCreateModel userData)
        {
            if (!ModelState.IsValid)
            {
                return(null);
            }                                        //can also simply code: if(!ModelState.IsValid) {return null;} then proceed with other code
            try
            {
                UserReturnModel user      = _accountRepo.Register(userData);
                ClaimsPrincipal principal = user.SetClaims();
                //HttpContext allows you to tell the application that the user just
                //logged in and sets the cookie, allowing the user to remain logged in.
                await HttpContext.SignInAsync(principal);

                return(user);
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e.Message);
            }
            return(null);
        }