public GetUserDetailsResponse GetUserDetails(GetUserDetailsRequest request)
        {
            GetUserDetailsResponse response = new GetUserDetailsResponse();
            Consumer consumer = null;

            try
            {
                using (UserDao dao = new UserDao())
                {
                    consumer = GetAuthUser(dao, request.user_id, request.auth_token, true);
                    if (consumer == null)
                    {
                        MakeNouserResponse(response);
                        return(response);
                    }
                    UsersHelper.CopyFromEntity(response, consumer);
                    response.has_resource = 1;
                    response.code         = 0;
                    response.message      = MessagesSource.GetMessage("user.details");
                    return(response);
                }
            }
            catch (Exception ex)
            {
                response.MakeExceptionResponse(ex);
                return(response);
            }
        }
Beispiel #2
0
        public GetUserDetailsResponse GetUserDetails(ISession session, GetUserDetailsRequest request)
        {
            var response = request.CreateResponse <GetUserDetailsResponse>();

            using (var uow = UnitOfWorkFactory.Create())
            {
                Specification <User> spec = null;
                if (request.UserId != 0)
                {
                    spec = UserSpecification.Id(request.UserId);
                }
                else if (!string.IsNullOrEmpty(request.Name))
                {
                    spec = UserSpecification.Name(request.Name);
                }
                else
                {
                    return(response); //invalid request
                }

                var user = uow.UsersRepository.FirstMatching(spec);
                if (user != null)
                {
                    response.User     = user.ProjectedAs <UserDto>();
                    response.IsFriend = session.User.Friends.Any(p => p.Id == user.Id);

                    uow.Attach(session.User);
                }
            }
            return(response);
        }
Beispiel #3
0
            public void GetUserDetails()
            {
                GetUserDetailsRequest  request  = new GetUserDetailsRequest(connection, testToken, testUser);
                GetUserDetailsResponse response = request.Send();

                Assert.AreEqual(response.StatusCode, System.Net.HttpStatusCode.OK);
            }
Beispiel #4
0
        public void Handle_ShouldGetUserDetails()
        {
            var name  = "Foo Bar";
            var token = "Foo.Token";

            var expected = new UserDto
            {
                Name  = name,
                Token = token
            };
            var request = new GetUserDetailsRequest
            {
                Name = name
            };

            _mockUserService.Setup(s => s.GetUserDetails(name)).ReturnsAsync(new UserEntity
            {
                Name  = name,
                Token = token
            });

            var result = _sut.Handle(request, It.IsAny <CancellationToken>()).Result;

            Assert.Equal(expected.Name, result.Name);
            Assert.Equal(expected.Token, result.Token);
        }
        public async Task <IActionResult> Index(GetUserDetailsRequest user)
        {
            var result = await _mediator.Send(user);

            if (result is null)
            {
                return(StatusCode(400));
            }
            return(Ok(result));
        }
Beispiel #6
0
        public GetUserDetailsResponse GetUserDetails(GetUserDetailsRequest req)
        {
            var target = db.Users.FirstOrDefault(u => u.Id == req.Id);

            if (target == null)
            {
                var errorMessage = "user is not found";

                return(new GetUserDetailsResponse(errorMessage, true));
            }

            return(new GetUserDetailsResponse(target));
        }
 public async Task <GetUserDetailsResponse> GetUserInformationAsync(GetUserDetailsRequest userDetails)
 {
     try
     {
         var context         = new UserDetailsContext();
         var userInformation = context.UserDetails.Where(user => user.UserEmail == userDetails.UserEmail).SingleOrDefault();
         GetUserDetailsResponse userResponse = new GetUserDetailsResponse();
         userResponse.FirstName   = userInformation.FirstName;
         userResponse.LastName    = userInformation.LastName;
         userResponse.PhoneNumber = userInformation.PhoneNumber;
         userResponse.UserEmail   = userInformation.UserEmail;
         userResponse.UserType    = ((UserAccessType)userInformation.UserTypeId).ToString();
         return(userResponse);
     }
     catch (Exception e)
     {
         throw;
         return(null);
     }
 }
        public ActionResult EditInfo()
        {
            string          connection  = ConfigurationManager.AppSettings["InternalAPIURL"];
            var             ctx         = Request.GetOwinContext();
            ClaimsPrincipal user        = ctx.Authentication.User;
            string          accessToken = user.Claims.FirstOrDefault(x => x.Type == "AccessToken").Value;
            string          userID      = user.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier).Value;

            GetUserDetailsRequest  userDetailRequest  = new GetUserDetailsRequest(connection, accessToken, new Guid(userID));
            GetUserDetailsResponse userDetailResponse = userDetailRequest.Send();

            EditInfo model = new EditInfo()
            {
                Nicknane  = userDetailResponse.NICKNAME,
                FirstName = userDetailResponse.FIRST_NAME,
                LastName  = userDetailResponse.LAST_NAME,
            };

            return(View(model));
        }
        public ActionResult Index()
        {
            string         connection  = ConfigurationManager.AppSettings["InternalAPIURL"];
            ClaimsIdentity identity    = new ClaimsIdentity(Request.GetOwinContext().Authentication.User.Identity);
            string         accessToken = identity.FindFirst("AccessToken").Value;
            string         userID      = identity.FindFirst(ClaimTypes.NameIdentifier).Value;

            GetUserDetailsRequest  detailRequest = new GetUserDetailsRequest(connection, accessToken, new Guid(userID));
            GetUserDetailsResponse model         = detailRequest.Send();

            if (model.StatusCode == System.Net.HttpStatusCode.OK)
            {
                return(View(model));
            }
            else
            {
                TempData["Errors"] = "There was an error processing your request";
                return(View());
            }
        }
Beispiel #10
0
 public Task <GetUserDetailsResponse> GetUserDetails(GetUserDetailsRequest request)
 {
     return(ConnectionManager.SendRequestAndWaitResponse <GetUserDetailsResponse>(request));
 }
Beispiel #11
0
 public static void CopyToEntity(Consumer consumer, GetUserDetailsRequest request)
 {
     consumer.ConsID   = request.user_id;
     consumer.AccToken = request.auth_token;// auth_token, source
 }
        public void OnAuthentication(AuthenticationContext filterContext)
        {
            //Get current user
            ClaimsPrincipal user = filterContext.HttpContext.User as ClaimsPrincipal;

            if (user != null && user.Identity.IsAuthenticated)
            {
                ClaimsIdentity identity    = new ClaimsIdentity(user.Identity);
                DateTime       expiresTime = DateTimeOffset.FromUnixTimeSeconds(long.Parse(identity.FindFirst(ClaimTypes.Expiration).Value)).LocalDateTime;

                if (expiresTime < DateTime.Now)
                {
                    string connection   = ConfigurationManager.AppSettings["InternalAPIURL"];
                    string refreshToken = identity.FindFirst("RefreshToken").Value;

                    RefreshRequest  refreshRequest  = new RefreshRequest(connection, refreshToken);
                    RefreshResponse refreshResponse = refreshRequest.Send();

                    GetUserDetailsRequest  userDetailRequest  = new GetUserDetailsRequest(connection, refreshResponse.access_token, new Guid(refreshResponse.user_id));
                    GetUserDetailsResponse userDetailResponse = userDetailRequest.Send();

                    if (refreshResponse.StatusCode == System.Net.HttpStatusCode.OK && userDetailResponse.StatusCode == System.Net.HttpStatusCode.OK)
                    {
                        //Update the user's claims
                        identity.RemoveClaim(identity.FindFirst("AccessToken"));
                        identity.RemoveClaim(identity.FindFirst(ClaimTypes.Expiration));
                        identity.RemoveClaim(identity.FindFirst(ClaimTypes.Name));
                        identity.RemoveClaim(identity.FindFirst(ClaimTypes.NameIdentifier));
                        identity.AddClaim(new Claim("AccessToken", refreshResponse.access_token));
                        identity.AddClaim(new Claim(ClaimTypes.Expiration, refreshResponse.expireTime));
                        identity.AddClaim(new Claim(ClaimTypes.Name, refreshResponse.user_nick));
                        identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, refreshResponse.user_id));

                        var roleClaims = identity.FindAll(ClaimTypes.Role);
                        foreach (Claim role in roleClaims)
                        {
                            identity.RemoveClaim(role);
                        }

                        if (userDetailResponse.PERMISSIONS.Administrator)
                        {
                            identity.AddClaim(new Claim(ClaimTypes.Role, "Administrator"));
                        }
                        if (userDetailResponse.PERMISSIONS.Developer)
                        {
                            identity.AddClaim(new Claim(ClaimTypes.Role, "Developer"));
                        }

                        var authenticationManager = filterContext.HttpContext.GetOwinContext().Authentication;
                        authenticationManager.SignOut();

                        AuthenticationProperties properties = new AuthenticationProperties {
                            IsPersistent = Convert.ToBoolean(identity.FindFirst(ClaimTypes.IsPersistent).Value)
                        };
                        authenticationManager.SignIn(properties, identity);

                        ClaimsPrincipal claimsPrincipal = new ClaimsPrincipal(identity);
                        filterContext.HttpContext.User = claimsPrincipal;
                    }
                    else
                    {
                        filterContext.HttpContext.GetOwinContext().Authentication.SignOut();
                    }
                }
            }
            else
            {
                filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary {
                    { "controller", "Account" }, { "action", "Login" }
                });
            }
        }
Beispiel #13
0
        public NegotiatedContentResult <GetUserDetailsResponse> PostGetUserDetails([FromBody] GetUserDetailsRequest request)
        {
            GetUserDetailsResponse resp = _userServices.GetUserDetails(request);

            return(Content(HttpStatusCode.OK, resp));
        }
Beispiel #14
0
 /// <remarks/>
 public void GetUserDetailsAsync(GetUserDetailsRequest GetUserDetailsRequest, object userState) {
     if ((this.GetUserDetailsOperationCompleted == null)) {
         this.GetUserDetailsOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetUserDetailsOperationCompleted);
     }
     this.InvokeAsync("GetUserDetails", new object[] {
                 GetUserDetailsRequest}, this.GetUserDetailsOperationCompleted, userState);
 }
Beispiel #15
0
 /// <remarks/>
 public void GetUserDetailsAsync(GetUserDetailsRequest GetUserDetailsRequest) {
     this.GetUserDetailsAsync(GetUserDetailsRequest, null);
 }
        public ActionResult Login(Login model)
        {
            if (ModelState.IsValid)
            {
                //make login request
                string connection = ConfigurationManager.AppSettings["InternalAPIURL"];

                LoginRequest  loginRequest  = new LoginRequest(connection, model.Email, model.password);
                LoginResponse loginResponse = loginRequest.Send();

                if (loginResponse.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    string accessToken = loginResponse.access_token;
                    Guid   userID      = new Guid(loginResponse.user_id);

                    GetUserDetailsRequest  userDetailRequest  = new GetUserDetailsRequest(connection, accessToken, userID);
                    GetUserDetailsResponse userDetailResponse = userDetailRequest.Send();
                    if (userDetailResponse.StatusCode == System.Net.HttpStatusCode.OK)
                    {
                        List <Claim> claims = new List <Claim>();
                        claims.Add(new Claim("AccessToken", loginResponse.access_token));
                        claims.Add(new Claim("RefreshToken", loginResponse.refresh_token));
                        claims.Add(new Claim(ClaimTypes.Name, loginResponse.user_nick));
                        claims.Add(new Claim(ClaimTypes.NameIdentifier, loginResponse.user_id));
                        claims.Add(new Claim(ClaimTypes.Expiration, loginResponse.expireTime));
                        claims.Add(new Claim(ClaimTypes.IsPersistent, model.RememberMe.ToString()));
                        if (userDetailResponse.PERMISSIONS.Administrator)
                        {
                            claims.Add(new Claim(ClaimTypes.Role, "Administrator"));
                        }
                        if (userDetailResponse.PERMISSIONS.Developer)
                        {
                            claims.Add(new Claim(ClaimTypes.Role, "Developer"));
                        }

                        ClaimsIdentity id = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);
                        var            authenticationManager = Request.GetOwinContext().Authentication;

                        AuthenticationProperties properties = new AuthenticationProperties {
                            IsPersistent = model.RememberMe
                        };
                        authenticationManager.SignIn(properties, id);

                        //redirect to register success, login success
                        TempData["Success"] = "You have successfully signed in!";
                        return(RedirectToAction("Index", "Account"));
                    }
                    else
                    {
                        TempData["Errors"] = "There was an error processing your request.";
                        return(View(model));
                    }
                }
                else
                {
                    if (loginResponse.StatusCode == System.Net.HttpStatusCode.NotFound)
                    {
                        TempData["Errors"] = "Your email and password do not match. Please try again.";
                    }
                    else if (loginResponse.StatusCode == System.Net.HttpStatusCode.NotAcceptable)
                    {
                        TempData["Resend"] = model.Email;
                    }
                    else
                    {
                        TempData["Errors"] = "There was an error processing your request. Please try again.";
                    }
                    return(View(model));
                }
            }
            else
            {
                return(View(model));
            }
        }