Exemplo n.º 1
0
        //[EnableCors(origins: "*", headers: "*", methods: "*")]
        public HttpResponseMessage UpdateCookie()
        {
            SSOReturnResult ret = new SSOReturnResult();
            SSOUserStatus   us  = new SSOUserStatus();

            string             req      = SSOHTTPRequestService.getDataInRequest(Request);
            SSOCookieInfor     ci       = SSOHTTPRequestService.getDataFromString <SSOCookieInfor>(req);
            SSOUserLoginInfors oldValue = null;

            if (ci != null && ci.Token != null && UserManagerService.CheckRequestAuthentication(ci.Token, out oldValue))
            {
                oldValue.UserCookie.Expires = ci.Expires;
                UserManagerService.UsersLoggedIn.AddOrUpdate(ci.Token, oldValue,
                                                             (key, existingVal) =>
                {
                    existingVal.UserCookie.Expires = oldValue.UserCookie.Expires;
                    return(existingVal);
                });

                ret.ReturnCode = HttpStatusCode.OK;
                ret.Message    = "Cập nhật thành công";
            }
            else
            {
                ret.ReturnCode = HttpStatusCode.BadRequest;
                ret.Message    = "Dữ liệu cập nhật không hợp lệ";
            }

            return(SSOHTTPRequestService.CreateResponseMessage(ret, HttpStatusCode.OK));
        }
Exemplo n.º 2
0
        //[EnableCors(origins: "*", headers: "*", methods: "*")]
        public HttpResponseMessage getUserStatus()
        {
            SSOUserStatus      us = new SSOUserStatus();
            SSOUserLoginInfors Us = null;

            string req = SSOHTTPRequestService.getDataInRequest(Request);
            string dt  = SSOHTTPRequestService.getDataFromString <string>(req);

            us.UserLoggedIn = UserManagerService.CheckRequestAuthentication(dt, out Us);

            return(SSOHTTPRequestService.CreateResponseMessage(us, HttpStatusCode.OK));
        }
Exemplo n.º 3
0
        //[EnableCors(origins: "*", headers: "*", methods: "*")]
        public HttpResponseMessage LogoutUser(string Token)
        {
            SSOUserLoginInfors Us = null;

            if (UserManagerService.CheckRequestAuthentication(Token, out Us))
            {
                var                  context = new HttpContextWrapper(HttpContext.Current);
                HttpRequestBase      request = context.Request;
                SSOHttpRequestParams par     = SSOHTTPRequestService.GetRequestParams(request);
                //var app = HttpContext.Current.ApplicationInstance as HttpApplication;
                UserManagerService.LogoutUser(par, SSOConstants.Cookie.AUTH_COOKIE, null);
            }

            SSOReturnResult ret = new SSOReturnResult();

            ret.ReturnCode = HttpStatusCode.OK;
            ret.Message    = "Logout thành công";

            return(SSOHTTPRequestService.CreateResponseMessage(ret, HttpStatusCode.OK));
        }
Exemplo n.º 4
0
        //Cập nhật thông tin người dùng
        public HttpResponseMessage UpdateUser()
        {
            string         message   = "";
            bool           isSuccess = false;
            string         req       = SSOHTTPRequestService.getDataInRequest(Request);
            SSOHtNguoiDung us        = SSOHTTPRequestService.getDataFromString <SSOHtNguoiDung>(req);

            if (us != null)
            {
                isSuccess = UserManagerService.UpdateUser(us, out message);
            }

            if (isSuccess)
            {
                return(SSOHTTPRequestService.CreateResponseMessage(message, HttpStatusCode.OK));
            }
            else
            {
                return(SSOHTTPRequestService.CreateResponseMessage(message, HttpStatusCode.InternalServerError));
            }
        }
Exemplo n.º 5
0
        //[EnableCors(origins: "*", headers: "*", methods: "*")]
        public HttpResponseMessage getUserInfors()
        {
            SSOUserLoginInfors Us = null, ret = null;

            string req                 = SSOHTTPRequestService.getDataInRequest(Request);
            SSOHtTokenRequestData Data = SSOHTTPRequestService.getDataFromString <SSOHtTokenRequestData>(req);
            bool check                 = false;

            if (UserManagerService.CheckRequestAuthentication(Data.Token, out Us))
            {
                if (Data.isTokenFromCookie || Us.FirstTimeToken)
                {
                    ret = AutoMapper.Mapper.Map <SSOUserLoginInfors, SSOUserLoginInfors>(Us);
                    ret.SuccessGetData = true;
                    ret.ThongBao       = "Lấy dữ liệu thành công";
                    ret.UserCookie     = null;
                    ret.FirstTimeToken = false;
                    Us.FirstTimeToken  = false;
                    UserManagerService.UsersLoggedIn.AddOrUpdate(Us.Token, Us,
                                                                 (key, existingVal) =>
                    {
                        existingVal.FirstTimeToken = Us.FirstTimeToken;
                        return(existingVal);
                    });
                    check = true;
                }
            }

            if (!check)
            {
                ret = new SSOUserLoginInfors();
                ret.SuccessGetData = false;
                ret.ThongBao       = "Yêu cầu không hợp lệ";
            }

            return(SSOHTTPRequestService.CreateResponseMessage(ret, HttpStatusCode.OK));
        }