Ejemplo n.º 1
0
        public async Task <IActionResult> Login([FromBody] LoginModel loginData)
        {
            if (loginData == null)
            {
                return(BadRequest());
            }

            try
            {
                var user = await dbContext.Users
                           .Include(u => u.ProfilePicture)
                           .FirstOrDefaultAsync(u => u.Email.Equals(loginData.Username));

                if (user == null)
                {
                    return(BadRequest("InvalidUserNamePassword"));
                }

                var res = userService.CheckPassword(user, loginData.Password);

                if (!res.Status)
                {
                    return(BadRequest("InvalidUserNamePassword"));
                }

                return(Json(OperationActionResult.Success(new ApplicationUserDTO
                {
                    Id = user.Id,
                    Email = user.Email,
                    UserName = user.UserName,
                    ProfileImage = user.ProfilePicture.Url
                })));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> RegisterUser([FromBody] ApplicationUserModel userData)
        {
            if (userData == null)
            {
                return(BadRequest());
            }

            try
            {
                var res = await userService.AddUser(userData);

                if (!res.Status)
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, res.Message));
                }

                return(Json(OperationActionResult.Success(res.Value)));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }