Ejemplo n.º 1
0
        public async Task <ResponseObject> GetUserProfile(Guid userId)
        {
            var result = await _profileRepo.GetUserProfile(userId);

            var loginUser = _mapper.Map <LoginUser>(result);

            return(_helper.BuildResponse("Success", loginUser, "Profile Details fetched successfully!", (int)HttpStatusCode.OK));
        }
        public async Task <ActionResult> GetAccessToken(Login Login)
        {
            try
            {
                var result = await _profileLogic.GetLogedInUserProfile(Login.UserName, Login.Password);

                if (result == null)
                {
                    return(Unauthorized(_helper.BuildResponse("Error", null, "Invalid Credentials", (int)HttpStatusCode.Unauthorized)));
                }

                var loggedInUserDetail = new UserDetail()
                {
                    UserId    = result.UserId,
                    UserName  = result.UserName,
                    Password  = result.Password,
                    FirstName = result.FirstName,
                    LastName  = result.LastName,
                    Role      = result.Role
                };
                var accessToken = await _authService.GetAccessToken(loggedInUserDetail);

                await _profileLogic.AddLogin(result.UserId, accessToken.Token, accessToken.Refreshtoken);

                if (accessToken == null)
                {
                    return(Unauthorized(_helper.BuildResponse("Error", null, "Invalid Credentials", (int)HttpStatusCode.Unauthorized)));
                }

                return(Ok(accessToken));
            }
            catch (Exception ex)
            {
                return(_helper.CreateApiError(ex));
            }
        }