/// <summary>
        /// Logs a user into the registered application. Email and password fields of
        /// user is used for this operation.
        /// </summary>
        /// <param name="email">Email of the user</param>
        /// <param name="password">Password of the user</param>
        /// <returns>The logged user</returns>
        public static NetmeraUser login(String email, String password)
        {
            NetmeraUser user = new NetmeraUser();

            try
            {
                RequestItem loginUserReqItem = new RequestItem();
                loginUserReqItem.setEmail(email);
                loginUserReqItem.setPassword(password);

                JObject jLogin = login(loginUserReqItem);
                if (jLogin != null)
                {
                    user = setCurrentUser(jLogin);
                }
                else
                {
                    throw new NetmeraException(NetmeraException.ErrorCode.EC_NULL_EXCEPTION, "Response of user login method is null");
                }
            }
            catch (WebException)
            {
                throw new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_REQUEST, "Web exception occurred in user login method");
            }
            catch (IOException)
            {
                throw new NetmeraException(NetmeraException.ErrorCode.EC_IO_EXCEPTION, "IO Exception occurred in user login method");
            }
            catch (JsonException)
            {
                throw new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_JSON, "Json in the response of user login method is invalid");
            }

            return(user);
        }
        /// <summary>
        /// Registers new user. Before calling this method email,password and
        /// nickname fields of the <see cref="NetmeraUser"/> should be set. Those are
        /// the compulsory fields. There are also optional name and surname fields.
        /// </summary>
        public void register()
        {
            try
            {
                RequestItem registerUserReqItem = new RequestItem();
                registerUserReqItem.setEmail(email);
                registerUserReqItem.setPassword(password);
                registerUserReqItem.setNickname(nickname);
                registerUserReqItem.setName(name);
                registerUserReqItem.setSurname(surname);

                JObject jUser = register(registerUserReqItem);

                setUser(jUser);
            }
            catch (WebException)
            {
                throw new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_REQUEST, "Request exception occurred while registering user");
            }
            catch (IOException)
            {
                throw new NetmeraException(NetmeraException.ErrorCode.EC_IO_EXCEPTION, "IO Exception occurred while registering user");
            }
            catch (JsonException)
            {
                throw new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_JSON, "Json in the response of register user method is invalid");
            }
        }
        /// <summary>
        /// Updates user info. Before calling this method email,password and nickname
        /// fields of the <see cref="NetmeraUser"/> should be set. Those are the
        /// compulsory fields.
        /// </summary>
        public void update()
        {
            JObject jProfile = null;
            JObject jAccount = null;

            try
            {
                RequestItem updateUserReqItem = new RequestItem();
                updateUserReqItem.setEmail(email);
                updateUserReqItem.setPassword(password);
                updateUserReqItem.setNickname(nickname);
                updateUserReqItem.setName(name);
                updateUserReqItem.setSurname(surname);

                if (nickname != null)
                {
                    jProfile = profileUpdate(updateUserReqItem);

                    setUser(jProfile);
                    if (password != null)
                    {
                        jAccount = accountUpdate(updateUserReqItem);
                    }
                }
                else if (password != null)
                {
                    jAccount = accountUpdate(updateUserReqItem);
                    setUser(jAccount);
                }
            }
            catch (WebException)
            {
                throw new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_REQUEST, "Web exception occurred while updating user");
            }
            catch (IOException)
            {
                throw new NetmeraException(NetmeraException.ErrorCode.EC_IO_EXCEPTION, "IO Exception occurred while updating user");
            }
            catch (JsonException)
            {
                throw new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_JSON, "Json in the response of update user method is invalid");
            }
        }
Exemple #4
0
        /// <summary>
        /// Logs a user into the registered application. Email and password fields of
        /// user is used for this operation.
        /// </summary>
        /// <param name="email">Email of the user</param>
        /// <param name="password">Password of the user</param>
        /// <param name="callback">Method called when user login operation finishes</param>
        public static void login(String email, String password, Action <NetmeraUser, Exception> callback)
        {
            clearSocialSessions((cleared, exception) =>
            {
                if (exception != null)
                {
                    if (callback != null)
                    {
                        callback(null, exception);
                    }
                }
                else if (cleared)
                {
                    NetmeraUser user = new NetmeraUser();
                    try
                    {
                        RequestItem loginUserReqItem = new RequestItem();
                        loginUserReqItem.setEmail(email);
                        loginUserReqItem.setPassword(password);

                        login(loginUserReqItem, (json, ex) =>
                        {
                            if (json == null || ex != null)
                            {
                                if (callback != null)
                                {
                                    callback(null, ex);
                                }
                            }
                            else
                            {
                                try
                                {
                                    user = setCurrentUser(json);
                                    if (callback != null)
                                    {
                                        callback(user, ex);
                                    }
                                }
                                catch (NetmeraException e)
                                {
                                    if (callback != null)
                                    {
                                        callback(null, e);
                                    }
                                }
                            }
                        });
                    }
                    catch (WebException)
                    {
                        if (callback != null)
                        {
                            callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_REQUEST, "Web exception occurred in user login method"));
                        }
                    }
                    catch (IOException)
                    {
                        if (callback != null)
                        {
                            callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_IO_EXCEPTION, "IO Exception occurred in user login method"));
                        }
                    }
                    catch (JsonException)
                    {
                        if (callback != null)
                        {
                            callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_JSON, "Json in the response of user login method is invalid"));
                        }
                    }
                }
                else
                {
                    if (callback != null)
                    {
                        callback(null, exception);
                    }
                }
            });
        }
Exemple #5
0
        /// <summary>
        /// Updates user info. Before calling this method email,password and nickname
        /// fields of the <see cref="NetmeraUser"/> should be set. Those are the
        /// compulsory fields.
        /// </summary>
        /// <param name="callback">Method called when user update operation finishes</param>
        public void update(Action <NetmeraUser, Exception> callback)
        {
            try
            {
                RequestItem updateUserReqItem = new RequestItem();
                updateUserReqItem.setEmail(email);
                updateUserReqItem.setPassword(password);
                updateUserReqItem.setNickname(nickname);
                updateUserReqItem.setName(name);
                updateUserReqItem.setSurname(surname);

                if (nickname != null)
                {
                    profileUpdate(updateUserReqItem, (jsonp, ex) =>
                    {
                        if (jsonp == null || ex != null)
                        {
                            if (callback != null)
                            {
                                callback(null, ex);
                            }
                        }
                        else
                        {
                            try
                            {
                                setUser(jsonp);
                                if (callback != null)
                                {
                                    callback(this, ex);
                                }

                                if (password != null)
                                {
                                    accountUpdate(updateUserReqItem, (jsona, e) =>
                                    {
                                        if (callback != null)
                                        {
                                            callback(this, e);
                                        }
                                    });
                                }
                                if (callback != null)
                                {
                                    callback(this, ex);
                                }
                            }
                            catch (NetmeraException e)
                            {
                                if (callback != null)
                                {
                                    callback(null, e);
                                }
                            }
                        }
                    });
                }
                else if (password != null)
                {
                    accountUpdate(updateUserReqItem, (jsona, ex) =>
                    {
                        if (jsona == null || ex != null)
                        {
                            if (callback != null)
                            {
                                callback(null, ex);
                            }
                        }
                        else
                        {
                            try
                            {
                                setUser(jsona);
                                if (callback != null)
                                {
                                    callback(this, ex);
                                }
                            }
                            catch (NetmeraException e)
                            {
                                if (callback != null)
                                {
                                    callback(null, e);
                                }
                            }
                        }
                    });
                }
            }
            catch (WebException)
            {
                if (callback != null)
                {
                    callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_REQUEST, "Web exception occurred while updating user"));
                }
            }
            catch (IOException)
            {
                if (callback != null)
                {
                    callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_IO_EXCEPTION, "IO Exception occurred while updating user"));
                }
            }
            catch (JsonException)
            {
                if (callback != null)
                {
                    callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_JSON, "Json in the response of update user method is invalid"));
                }
            }
        }
Exemple #6
0
        /// <summary>
        /// Registers new user. Before calling this method email,password and
        /// nickname fields of the <see cref="NetmeraUser"/> should be set. Those are
        /// the compulsory fields. There are also optional name and surname fields.
        /// </summary>
        /// <param name="callback">method called when user register operation finishes</param>
        public void register(Action <NetmeraUser, Exception> callback)
        {
            try
            {
                RequestItem registerUserReqItem = new RequestItem();
                registerUserReqItem.setEmail(email);
                registerUserReqItem.setPassword(password);
                registerUserReqItem.setNickname(nickname);
                registerUserReqItem.setName(name);
                registerUserReqItem.setSurname(surname);

                register(registerUserReqItem, (json, ex) =>
                {
                    if (json == null || ex != null)
                    {
                        if (callback != null)
                        {
                            callback(null, ex);
                        }
                    }
                    else
                    {
                        try
                        {
                            setUser(json);
                            if (callback != null)
                            {
                                callback(this, ex);
                            }
                        }
                        catch (NetmeraException e)
                        {
                            if (callback != null)
                            {
                                callback(null, e);
                            }
                        }
                    }
                });
            }
            catch (WebException)
            {
                if (callback != null)
                {
                    callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_REQUEST, "Request exception occurred while registering user"));
                }
            }
            catch (IOException)
            {
                if (callback != null)
                {
                    callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_IO_EXCEPTION, "IO Exception occurred while registering user"));
                }
            }
            catch (JsonException)
            {
                if (callback != null)
                {
                    callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_JSON, "Json in the response of register user method is invalid"));
                }
            }
        }