示例#1
0
        public AssignRolesToUserOutput AssignRolesToUser(AssignRolesToUserInput input)
        {
            try
            {
                RestHTTP    http = new RestHTTP();
                RestRequest req  = new RestRequest("api/accounts/assignRolesToUser", RestSharp.Method.POST);
                req.AddHeader("Content-Type", "application/json");
                req.AddHeader("Authorization", "Bearer " + input.AccessToken);
                req.AddJsonBody(input);


                var response = http.HttpPost <object>(req);

                AssignRolesToUserOutput output = new AssignRolesToUserOutput();
                output.Id = JsonConvert.DeserializeObject <string>(response.ToString());

                return(output);
            }
            catch (Exception ex)
            {
                WriteLogFile.Append("AssignRolesToUser : ");
                WriteLogFile.Append(ex.Message);
                WriteLogFile.Append(ex.StackTrace);
            }
            return(null);
        }
示例#2
0
        public UpdateUserInfoOutput UpdateUserInfo(UpdateUserInfoInput input)
        {
            try
            {
                RestHTTP    http = new RestHTTP();
                RestRequest req  = null;
                if (!string.IsNullOrEmpty(input.Id))
                {
                    req = new RestRequest("api/accounts/update", RestSharp.Method.POST);
                }

                req.AddHeader("Authorization", "Bearer " + input.AccessToken);
                req.RequestFormat = DataFormat.Json;
                req.AddJsonBody(input);

                var response = http.HttpPost <UpdateUserInfoOutput>(req);

                return(response);
            }
            catch (Exception ex)
            {
                WriteLogFile.Append("UpdateUserInfo : ");
                WriteLogFile.Append(ex.Message);
                WriteLogFile.Append(ex.StackTrace);
                return(default(UpdateUserInfoOutput));
            }
        }
        public async Task <IHttpActionResult> GetAccessTokenByUserName(GetAccessTokenByUserNameInput input)
        {
            RestHTTP http = new RestHTTP();

            RestSharp.RestRequest req = new RestSharp.RestRequest("/oauth/token", RestSharp.Method.POST);
            input.grant_type = "password";
            req.AddObject(input);

            GetAccessTokenByUserNameOutput output = http.HttpPost <GetAccessTokenByUserNameOutput>(req);

            if (output != null && !string.IsNullOrEmpty(output.AccessToken))
            {
                var user = await this.AppUserManager.FindByNameAsync(input.username);

                if (user != null)
                {
                    output.CurrentUserID     = user.Id;
                    output.TwoFactorAuthFlag = user.TwoFactorEnabled;
                    UserReturnModel userSession = this.TheModelFactory.Create(user);
                    output.UserSession = new UserReturnModel();
                    output.UserSession = userSession;
                }
            }

            return(Ok(output));
        }
示例#4
0
        public RegisterExternalOutput RegisterExternal(RegisterExternalInput input)
        {
            RestHTTP http = new RestHTTP();

            RestSharp.RestRequest req = new RestSharp.RestRequest("api/accounts/RegisterExternal", RestSharp.Method.POST);
            req.AddJsonBody(input);

            var response = http.HttpPost <RegisterExternalOutput>(req);

            return(response);
        }
示例#5
0
        //Private Methods
        private LoginByLoginTokenOutput LoginByLoginToken(string accessToken)
        {
            var accessTokenObj = _CT.aToken.Deserialize(accessToken);

            LoginByLoginTokenInput Input = new LoginByLoginTokenInput()
            {
                LoginToken = accessTokenObj.AccessToken
            };
            RestHTTP http = new RestHTTP();

            RestSharp.RestRequest req = new RestSharp.RestRequest("api/auth/LoginByLoginToken", RestSharp.Method.POST);
            req.AddObject(Input);

            var response = http.HttpPost <LoginByLoginTokenOutput>(req);

            return(response);
        }
示例#6
0
        //Public Methods
        public RegisterUserOutput RegisterUser(RegisterUserInput input)
        {
            try
            {
                RestHTTP    http = new RestHTTP();
                RestRequest req  = new RestRequest("api/accounts/create", RestSharp.Method.POST);
                req.AddJsonBody(input);
                RegisterUserOutput response = http.HttpPost <RegisterUserOutput>(req);

                return(response);
            }
            catch (Exception ex)
            {
                WriteLogFile.Append("RegisterUser : ");
                WriteLogFile.Append(ex.Message);
                WriteLogFile.Append(ex.StackTrace);
            }
            return(null);
        }
示例#7
0
        public ForgotPasswordOutput ForgotPassword(ForgotPasswordInput input)
        {
            try
            {
                RestHTTP    http = new RestHTTP();
                RestRequest req  = new RestRequest("api/accounts/ForgotPassword", RestSharp.Method.POST);
                req.AddHeader("Content-Type", "application/json");
                req.AddJsonBody(input);
                ForgotPasswordOutput response = http.HttpPost <ForgotPasswordOutput>(req);

                return(response);
            }
            catch (Exception ex)
            {
                WriteLogFile.Append("ForgotPassword : ");
                WriteLogFile.Append(ex.Message);
                WriteLogFile.Append(ex.StackTrace);
            }
            return(null);
        }
示例#8
0
        public ChangePasswordOutput ChangePassword(ChangePasswordInput input)
        {
            try
            {
                RestHTTP    http = new RestHTTP();
                RestRequest req  = new RestRequest("api/accounts/ChangePassword", RestSharp.Method.POST);
                req.AddHeader("Content-Type", "application/json");
                req.AddHeader("Authorization", "Bearer " + input.AccessToken);
                req.AddJsonBody(input);
                ChangePasswordOutput response = http.HttpPost <ChangePasswordOutput>(req);

                return(response);
            }
            catch (Exception ex)
            {
                WriteLogFile.Append("ConfirmPassword : ");
                WriteLogFile.Append(ex.Message);
                WriteLogFile.Append(ex.StackTrace);
            }
            return(null);
        }
示例#9
0
        public DeleteUserOutput DeleteUser(DeleteUserInput input)
        {
            try
            {
                RestHTTP    http = new RestHTTP();
                RestRequest req  = new RestRequest("api/accounts/delete", RestSharp.Method.DELETE);
                req.AddHeader("Content-Type", "application/json");
                req.AddHeader("Authorization", "Bearer " + input.AccessToken);
                req.AddJsonBody(input);
                DeleteUserOutput response = http.HttpPost <DeleteUserOutput>(req);

                return(response);
            }
            catch (Exception ex)
            {
                WriteLogFile.Append("DeleteUser : ");
                WriteLogFile.Append(ex.Message);
                WriteLogFile.Append(ex.StackTrace);
            }
            return(null);
        }
示例#10
0
        public UpdateRoleOutput UpdateRole(UpdateRoleInput input)
        {
            try
            {
                RestHTTP    http = new RestHTTP();
                RestRequest req  = new RestRequest("api/roles/update", RestSharp.Method.POST);
                req.AddHeader("Content-Type", "application/json");
                req.AddHeader("Authorization", "Bearer " + input.AccessToken);
                req.AddJsonBody(input);
                UpdateRoleOutput response = http.HttpPost <UpdateRoleOutput>(req);

                return(response);
            }
            catch (Exception ex)
            {
                WriteLogFile.Append("UpdateRole : ");
                WriteLogFile.Append(ex.Message);
                WriteLogFile.Append(ex.StackTrace);
            }
            return(null);
        }