Пример #1
0
        public CreateUserResponse CreateUser(string accessToken, string username, string password, string firstName, string lastName, string mobilePhone, string email, string parent)
        {
            var parameters = new Dictionary <String, String>()
            {
                { "username", username },
                { "password", password },
                { "first_name", firstName },
                { "last_name", lastName },
                { "mobile_phone", mobilePhone },
                { "email", email },
                { "parent", parent },
            };

            var headers = new Dictionary <String, String>()
            {
                { "Authorization", "Bearer " + accessToken }
            };

            Response response = ServerConnetivityHelper.post("/api/v1/admin/user/?format=json", parameters, headers);

            if (response.getResponseCode() == 201)
            {
                byte[] byteArray = Encoding.UTF8.GetBytes(response.getContent());
                var    stream    = new MemoryStream(byteArray);

                var jsonResponse = (JsonObject)JsonValue.Load(stream);

                return(new CreateUserResponse(
                           response.getResponseCode()
                           , this.getString(jsonResponse, JSON_CREATE_USER_USERNAME_FIELD)
                           , this.getString(jsonResponse, JSON_CREATE_USER_FIRST_NAME_FIELD)
                           , this.getString(jsonResponse, JSON_CREATE_USER_LAST_NAME_FIELD)
                           , this.getString(jsonResponse, JSON_CREATE_USER_DN_FIELD)
                           , this.getString(jsonResponse, JSON_CREATE_USER_DB_MOBILE_PHONE_FIELD)
                           , this.getString(jsonResponse, JSON_CREATE_USER_DB_EMAIL_FIELD)
                           , this.getString(jsonResponse, JSON_CREATE_USER_LDAP_MOBILE_PHONE_FIELD)
                           , this.getString(jsonResponse, JSON_CREATE_USER_LDAP_EMAIL_FIELD)
                           , (this.getString(jsonResponse, JSON_CREATE_USER_STORAGE_FIELD) != null ? this.getUserStorage(jsonResponse, JSON_CREATE_USER_STORAGE_FIELD) : null)
                           ));
            }
            else
            {
                return(new CreateUserResponse(response.getResponseCode(), getErrors(response.getContent())));
            }
        }
Пример #2
0
        public AuthenticationResponse Authenticate(String username, String password, String transactionId)
        {
            var parameters = new Dictionary <String, String>()
            {
                { "username", username },
                { "password", password },
                { "transaction_id", transactionId }
            };


            var headers = new Dictionary <String, String>()
            {
                { "Authorization", "Bearer " + AccessToken }
            };

            Response response = ServerConnetivityHelper.post("/api/v1/auth/authenticate/?format=json", parameters, headers);

            if (response.getResponseCode() == 200 || response.getResponseCode() == 401)
            {
                // convert string to stream
                byte[] byteArray = Encoding.UTF8.GetBytes(response.getContent());
                var    stream    = new MemoryStream(byteArray);

                var jsonResponse = (JsonObject)JsonValue.Load(stream);

                return(new AuthenticationResponse(
                           response.getResponseCode()
                           , this.getAuthenticationCode(jsonResponse, JSON_AUTH_CODE_FIELD)
                           , this.getString(jsonResponse, JSON_AUTH_TRANSACTION_FIELD)
                           , this.getString(jsonResponse, JSON_AUTH_USERNAME_ID_FIELD)
                           , this.getString(jsonResponse, JSON_AUTH_REPLY_MESSAGE_FIELD)
                           , this.getString(jsonResponse, JSON_AUTH_DETAIL_FIELD)
                           , this.getReplyCode(jsonResponse, JSON_AUTH_REPLY_CODE_FIELD)
                           ));
            }
            else
            {
                return(new AuthenticationResponse(response.getResponseCode(), getErrors(response.getContent())));
            }
        }