Exemplo n.º 1
0
        /// <summary>
        /// Attempts to create a Photon Cloud Account asynchronously.
        /// Once your callback is called, check ReturnCode, Message and AppId to get the result of this attempt.
        /// </summary>
        /// <param name="email">Email of the account.</param>
        /// <param name="origin">Marks which channel created the new account (if it's new).</param>
        /// <param name="serviceType">Defines which type of Photon-service is being requested.</param>
        /// <param name="callback">Called when the result is available.</param>
        public void RegisterByEmail(string email, Origin origin, string serviceType, Action <AccountService> callback = null)
        {
            this.registrationCallback = callback;
            this.AppId      = string.Empty;
            this.AppId2     = string.Empty;
            this.Message    = string.Empty;
            this.ReturnCode = -1;

            string url = this.RegistrationUri(email, (byte)origin, serviceType);

            PhotonEditorUtils.StartCoroutine(
                PhotonEditorUtils.HttpGet(url,
                                          (s) =>
            {
                this.ParseResult(s);
                if (this.registrationCallback != null)
                {
                    this.registrationCallback(this);
                }
            },
                                          (e) =>
            {
                this.Message = e;
                if (this.registrationCallback != null)
                {
                    this.registrationCallback(this);
                }
            })
                );
        }
Exemplo n.º 2
0
        public bool RegisterByEmail(AccountServiceRequest request, Action <AccountServiceResponse> callback = null,
                                    Action <string> errorCallback = null)
        {
            if (request == null)
            {
                Debug.LogError("Registration request is null");
                return(false);
            }

            string fullUrl = GetUrlWithQueryStringEscaped(request);

            RequestHeaders["x-functions-key"] = string.IsNullOrEmpty(CustomToken) ? DefaultToken : CustomToken;

            //Debug.LogWarningFormat("Full URL {0}", fullUrl);
            PhotonEditorUtils.StartCoroutine(
                PhotonEditorUtils.HttpPost(fullUrl,
                                           RequestHeaders,
                                           null,
                                           s =>
            {
                //Debug.LogWarningFormat("received response {0}", s);
                if (string.IsNullOrEmpty(s))
                {
                    if (errorCallback != null)
                    {
                        errorCallback(
                            "Server's response was empty. Please register through account website during this service interruption.");
                    }
                }
                else
                {
                    AccountServiceResponse ase = this.ParseResult(s);
                    if (ase == null)
                    {
                        if (errorCallback != null)
                        {
                            errorCallback(
                                "Error parsing registration response. Please try registering from account website");
                        }
                    }
                    else if (callback != null)
                    {
                        callback(ase);
                    }
                }
            },
                                           e =>
            {
                if (errorCallback != null)
                {
                    errorCallback(e);
                }
            })
                );
            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Attempts to create a Photon Cloud Account asynchronously. Blocked while RequestPendingResult is true.
        /// </summary>
        /// <remarks>
        /// Once your callback is called, check ReturnCode, Message and AppId to get the result of this attempt.
        /// </remarks>
        /// <param name="email">Email of the account.</param>
        /// <param name="serviceTypes">Defines which type of Photon-service is being requested.</param>
        /// <param name="callback">Called when the result is available.</param>
        /// <param name="errorCallback">Called when the request failed.</param>
        public bool RegisterByEmail(string email, List <ServiceTypes> serviceTypes, Action <AccountServiceResponse> callback = null, Action <string> errorCallback = null)
        {
            if (this.RequestPendingResult)
            {
                Debug.LogError("Registration request pending result. Not sending another.");
                return(false);
            }

            if (!IsValidEmail(email))
            {
                Debug.LogErrorFormat("Email \"{0}\" is not valid", email);
                return(false);
            }

            string serviceTypeString = GetServiceTypesFromList(serviceTypes);

            if (string.IsNullOrEmpty(serviceTypeString))
            {
                Debug.LogError("serviceTypes string is null or empty");
                return(false);
            }

            string fullUrl = GetUrlWithQueryStringEscaped(email, serviceTypeString);

            RequestHeaders["x-functions-key"] = string.IsNullOrEmpty(CustomToken) ? DefaultToken : CustomToken;


            this.RequestPendingResult = true;

            PhotonEditorUtils.StartCoroutine(
                PhotonEditorUtils.HttpPost(fullUrl,
                                           RequestHeaders,
                                           null,
                                           s =>
            {
                this.RequestPendingResult = false;
                //Debug.LogWarningFormat("received response {0}", s);
                if (string.IsNullOrEmpty(s))
                {
                    if (errorCallback != null)
                    {
                        errorCallback("Server's response was empty. Please register through account website during this service interruption.");
                    }
                }
                else
                {
                    AccountServiceResponse ase = this.ParseResult(s);
                    if (ase == null)
                    {
                        if (errorCallback != null)
                        {
                            errorCallback("Error parsing registration response. Please try registering from account website");
                        }
                    }
                    else if (callback != null)
                    {
                        callback(ase);
                    }
                }
            },
                                           e =>
            {
                this.RequestPendingResult = false;
                if (errorCallback != null)
                {
                    errorCallback(e);
                }
            })
                );
            return(true);
        }