コード例 #1
0
 void callApiAsync(String targentStep)
 {
     if (AppStoreOnboardApi.tokenInfo.access_token == null)
     {
         UnityOAuth.GetAuthorizationCodeAsync(AppStoreOnboardApi.oauthClientId, (response) => {
             if (response.AuthCode != null)
             {
                 string authcode         = response.AuthCode;
                 UnityWebRequest request = AppStoreOnboardApi.GetAccessToken(authcode);
                 TokenInfo tokenInfoResp = new TokenInfo();
                 ReqStruct reqStruct     = new ReqStruct();
                 reqStruct.request       = request;
                 reqStruct.resp          = tokenInfoResp;
                 reqStruct.targetStep    = targentStep;
                 requestQueue.Enqueue(reqStruct);
             }
             else
             {
                 Debug.Log("Failed: " + response.Exception.ToString());
                 isOperationRunning = false;
             }
         });
     }
     else
     {
         UnityWebRequest request    = AppStoreOnboardApi.GetUserId();
         UserIdResponse  userIdResp = new UserIdResponse();
         ReqStruct       reqStruct  = new ReqStruct();
         reqStruct.request    = request;
         reqStruct.resp       = userIdResp;
         reqStruct.targetStep = targentStep;
         requestQueue.Enqueue(reqStruct);
     }
 }
コード例 #2
0
        public async Task <IHttpActionResult> SendOTP(string email, String UserId)
        {
            try
            {
                var OTP = _unitOfWork.GetForgotPasswordRepository().SaveOTP(new Common.DTO.ForgotPasswordDTO()
                {
                    OTP               = GetOTP(),
                    UserId            = UserId,
                    TokenCreationDate = DateTime.Now
                });
                await _unitOfWork.Save();

                if (!string.IsNullOrEmpty(email))
                {
                    SendEmail(OTP, email);
                }
                var userIdResponse = new UserIdResponse()
                {
                    UserId = UserId
                };
                return(Ok(userIdResponse));
            }
            catch (Exception e)
            {
                return(InternalServerError(e));
            }
        }
コード例 #3
0
        /// <summary>
        /// Abfrage der UserId
        /// </summary>
        /// <param name="UserName">Username oder Email-Adresse</param>
        /// <param name="Password">Das zum UserName dazugehörige Passwort</param>
        /// <returns>Die zum Account dazugehörige UserId</returns>
        public UserIdResponse GetUserId(string UserName, string Password)
        {
            // Hypothese: Login schlägt fehl - es kann keine UserId ermittelt werden
            var userId = string.Empty;

            var db = new ApplicationDbContext();

            ApplicationUser user = null;

            //Überprüfen ob Mail
            if (UserName.Contains("@"))
            {
                //Suche ob Mail vorhanden
                var tempUser = UserManager.FindByEmail(UserName);

                if (tempUser != null)
                {
                    //wenn was gefunden wurde, Überprüfen ob PW stimmt
                    user = UserManager.Find(tempUser.UserName, Password);
                    //wenn pw vorhanden userID abfragen
                    if (user != null)
                    {
                        userId = user.Id;
                    }
                }
            }
            //Übergebener string ist evtl Loginname
            else
            {
                //Überprüfen ob vorhanden und PW stimmt
                user = UserManager.Find(UserName, Password);

                //wenn user vorhanden stimmt userID abfragen
                if (user != null)
                {
                    userId = user.Id;
                }
            }

            // jetzt steht in jedem Fall etwas sinnvolles in der userId drin!
            // ein guter Zeitpunkt, um die "Response" zu erstellen
            var response = new UserIdResponse
            {
                UserId = userId,
            };

            return(response);
        }
コード例 #4
0
        public UserIdResponse  GetUserId(string UserName, string Password)
        {
            // Hypothese: Login schlägt fehl - es kann keine UserId ermittelt werden
            var userId = string.Empty;

            var userService = new UserService();
            var db          = new ApplicationDbContext();
            var UserIdRes   = new UserIdResponse();

            ApplicationUser user = null;

            //Überprüfen ob Mail
            if (UserName.Contains("@"))
            {
                //Suche ob Mail vorhanden
                var tempUser = userService.FindByEMail(UserName);

                if (tempUser != null)
                {
                    //wenn was gefunden wurde, Überprüfen ob PW stimmt
                    user = userService.UserManager.Find(tempUser.UserName, Password);
                    //wenn pw vorhanden userID abfragen
                    if (user != null)
                    {
                        //UserID Abfragen
                        userId = user.Id;
                    }
                }
            }
            //Übergebener string ist evtl Loginname
            else
            {
                //Überprüfen ob vorhanden und PW stimmt
                user = userService.UserManager.Find(UserName, Password);

                //wenn user vorhanden stimmt userID abfragen
                if (user != null)
                {
                    //UserID Abfragen
                    userId = user.Id;
                }
            }

            UserIdRes.UserId = userId;
            //Rückgabe des UserId-Response
            return(UserIdRes);
        }
コード例 #5
0
        public async void Initialize(INavigationParameters parameters)
        {
            bool isAuthorized = await AuthorizationService.Authorize();

            if (!isAuthorized)
            {
                return;
            }
            Post = parameters.GetValue <Post>("post");
            var useridTask      = ApiService.GetUserIdAsync();
            var datesTask       = ApiService.GetReservationDatesAsync(Post.CarId);
            var reserveTypeTask = ApiService.GetReservationTypesAsync();

            await Task.WhenAll(useridTask, datesTask, reserveTypeTask);

            HashSet <HttpResponseMessage> list =
                new HashSet <HttpResponseMessage>()
            {
                useridTask.Result, datesTask.Result, reserveTypeTask.Result
            };

            if (list.Any(t => !t.IsSuccessStatusCode))
            {
                await DialogService.DisplayAlertAsync("Error", "Failed to load data", "Ok");

                await NavigationService.GoBackAsync();
            }
            else
            {
                string useridJson = await useridTask.Result.Content.ReadAsStringAsync();

                string datesJson = await datesTask.Result.Content.ReadAsStringAsync();

                string reserveTypesJson = await reserveTypeTask.Result.Content.ReadAsStringAsync();

                BlackoutDates       = JsonConvert.DeserializeObject <ObservableCollection <DateTime> >(datesJson);
                ReservationTypeList = JsonConvert.DeserializeObject <ObservableCollection <ReservationType> >(reserveTypesJson);
                UserIdResponse userIdResponse = JsonConvert.DeserializeObject <UserIdResponse>(useridJson);
                NewReservation.ClientId = userIdResponse.UserId;
                NewReservation.CarId    = Post.CarId;
            }
        }
コード例 #6
0
        public async Task <IHttpActionResult> FindUser(string userName)
        {
            try
            {
                ApplicationUser user = await _repo.FindUser(userName);

                if (user == null)
                {
                    return(NotFound());
                }
                else
                {
                    var OTP = _unitOfWork.GetForgotPasswordRepository().SaveOTP(new Common.DTO.ForgotPasswordDTO()
                    {
                        OTP               = GetOTP(),
                        UserId            = user.Id,
                        TokenCreationDate = DateTime.Now
                    });
                    await _unitOfWork.Save();

                    if (!string.IsNullOrEmpty(user.Email))
                    {
                        SendEmail(OTP, user.Email);
                    }
                    var userIdResponse = new UserIdResponse()
                    {
                        UserId = user.Id
                    };
                    return(Ok(userIdResponse));
                }
            }
            catch (Exception e)
            {
                return(InternalServerError(e));
            }
        }
コード例 #7
0
        void CheckRequestUpdate()
        {
            if (requestQueue.Count <= 0)
            {
                return;
            }

            ReqStruct       reqStruct = requestQueue.Dequeue();
            UnityWebRequest request   = reqStruct.request;
            GeneralResponse resp      = reqStruct.resp;

            if (request != null && request.isDone)
            {
                if (request.error != null)
                {
                    Debug.LogError(request.error);
                    isOperationRunning = false;
                }
                else
                {
                    if (request.downloadHandler.text.Contains(AppStoreOnboardApi.tokenExpiredInfo))
                    {
                        UnityWebRequest newRequest    = AppStoreOnboardApi.RefreshToken();
                        TokenInfo       tokenInfoResp = new TokenInfo();
                        ReqStruct       newReqStruct  = new ReqStruct();
                        newReqStruct.request    = newRequest;
                        newReqStruct.resp       = tokenInfoResp;
                        newReqStruct.targetStep = reqStruct.targetStep;
                        requestQueue.Enqueue(newReqStruct);
                    }
                    else
                    {
                        if (resp.GetType() == typeof(TokenInfo))
                        {
                            resp = JsonUtility.FromJson <TokenInfo> (request.downloadHandler.text);
                            AppStoreOnboardApi.tokenInfo.access_token = ((TokenInfo)resp).access_token;
                            if (AppStoreOnboardApi.tokenInfo.refresh_token == null || AppStoreOnboardApi.tokenInfo.refresh_token == "")
                            {
                                AppStoreOnboardApi.tokenInfo.refresh_token = ((TokenInfo)resp).refresh_token;
                            }
                            UnityWebRequest newRequest   = AppStoreOnboardApi.GetUserId();
                            UserIdResponse  userIdResp   = new UserIdResponse();
                            ReqStruct       newReqStruct = new ReqStruct();
                            newReqStruct.request    = newRequest;
                            newReqStruct.resp       = userIdResp;
                            newReqStruct.targetStep = reqStruct.targetStep;
                            requestQueue.Enqueue(newReqStruct);
                        }
                        else if (resp.GetType() == typeof(UserIdResponse))
                        {
                            resp = JsonUtility.FromJson <UserIdResponse> (request.downloadHandler.text);
                            AppStoreOnboardApi.userId = ((UserIdResponse)resp).sub;
                            UnityWebRequest newRequest   = AppStoreOnboardApi.GetOrgId(Application.cloudProjectId);
                            OrgIdResponse   orgIdResp    = new OrgIdResponse();
                            ReqStruct       newReqStruct = new ReqStruct();
                            newReqStruct.request    = newRequest;
                            newReqStruct.resp       = orgIdResp;
                            newReqStruct.targetStep = reqStruct.targetStep;
                            requestQueue.Enqueue(newReqStruct);
                        }
                        else if (resp.GetType() == typeof(OrgIdResponse))
                        {
                            resp = JsonUtility.FromJson <OrgIdResponse> (request.downloadHandler.text);
                            AppStoreOnboardApi.orgId = ((OrgIdResponse)resp).org_foreign_key;
                            UnityWebRequest newRequest   = AppStoreOnboardApi.GetOrgRoles();
                            OrgRoleResponse orgRoleResp  = new OrgRoleResponse();
                            ReqStruct       newReqStruct = new ReqStruct();
                            newReqStruct.request    = newRequest;
                            newReqStruct.resp       = orgRoleResp;
                            newReqStruct.targetStep = reqStruct.targetStep;
                            requestQueue.Enqueue(newReqStruct);
                        }
                        else if (resp.GetType() == typeof(OrgRoleResponse))
                        {
                            resp = JsonUtility.FromJson <OrgRoleResponse> (request.downloadHandler.text);
                            List <string> roles = ((OrgRoleResponse)resp).roles;
                            if (roles.Contains("owner"))
                            {
                                ownerAuthed = true;
                                if (reqStruct.targetStep == STEP_GET_CLIENT)
                                {
                                    UnityWebRequest            newRequest        = AppStoreOnboardApi.GetUnityClientInfo(Application.cloudProjectId);
                                    UnityClientResponseWrapper clientRespWrapper = new UnityClientResponseWrapper();
                                    ReqStruct newReqStruct = new ReqStruct();
                                    newReqStruct.request    = newRequest;
                                    newReqStruct.resp       = clientRespWrapper;
                                    newReqStruct.targetStep = reqStruct.targetStep;
                                    requestQueue.Enqueue(newReqStruct);
                                }
                                else if (reqStruct.targetStep == STEP_UPDATE_CLIENT)
                                {
                                    UnityClientInfo unityClientInfo = new UnityClientInfo();
                                    unityClientInfo.ClientId = unityClientID.stringValue;
                                    string callbackUrl = callbackUrl_in_memory;
                                    // read xiaomi from user input
                                    XiaomiSettings xiaomi = new XiaomiSettings();
                                    xiaomi.appId     = xiaomiAppID.stringValue;
                                    xiaomi.appKey    = xiaomiAppKey.stringValue;
                                    xiaomi.appSecret = appSecret_in_memory;
                                    UnityWebRequest     newRequest   = AppStoreOnboardApi.UpdateUnityClient(Application.cloudProjectId, unityClientInfo, xiaomi, callbackUrl);
                                    UnityClientResponse clientResp   = new UnityClientResponse();
                                    ReqStruct           newReqStruct = new ReqStruct();
                                    newReqStruct.request    = newRequest;
                                    newReqStruct.resp       = clientResp;
                                    newReqStruct.targetStep = reqStruct.targetStep;
                                    requestQueue.Enqueue(newReqStruct);
                                }
                                else if (reqStruct.targetStep == STEP_UPDATE_CLIENT_SECRET)
                                {
                                    string              clientId     = unityClientID.stringValue;
                                    UnityWebRequest     newRequest   = AppStoreOnboardApi.UpdateUnityClientSecret(clientId);
                                    UnityClientResponse clientResp   = new UnityClientResponse();
                                    ReqStruct           newReqStruct = new ReqStruct();
                                    newReqStruct.request    = newRequest;
                                    newReqStruct.resp       = clientResp;
                                    newReqStruct.targetStep = reqStruct.targetStep;
                                    requestQueue.Enqueue(newReqStruct);
                                }
                            }
                            else if (roles.Contains("user") || roles.Contains("manager"))
                            {
                                ownerAuthed = false;
                                if (reqStruct.targetStep == STEP_GET_CLIENT)
                                {
                                    UnityWebRequest            newRequest        = AppStoreOnboardApi.GetUnityClientInfo(Application.cloudProjectId);
                                    UnityClientResponseWrapper clientRespWrapper = new UnityClientResponseWrapper();
                                    ReqStruct newReqStruct = new ReqStruct();
                                    newReqStruct.request    = newRequest;
                                    newReqStruct.resp       = clientRespWrapper;
                                    newReqStruct.targetStep = reqStruct.targetStep;
                                    requestQueue.Enqueue(newReqStruct);
                                }
                                else
                                {
                                    Debug.LogError("Permision denied.");
                                    isOperationRunning = false;
                                }
                            }
                            else
                            {
                                Debug.LogError("Permision denied.");
                                isOperationRunning = false;
                            }
                        }
                        else if (resp.GetType() == typeof(UnityClientResponseWrapper))
                        {
                            string raw = "{ \"array\": " + request.downloadHandler.text + "}";
                            resp = JsonUtility.FromJson <UnityClientResponseWrapper> (raw);
                            // only one element in the list
                            if (((UnityClientResponseWrapper)resp).array.Length > 0)
                            {
                                UnityClientResponse unityClientResp = ((UnityClientResponseWrapper)resp).array [0];
                                unityClientID.stringValue           = unityClientResp.client_id;
                                unityClientKey.stringValue          = unityClientResp.client_secret;
                                unityClientRSAPublicKey.stringValue = unityClientResp.channel.publicRSAKey;
                                clientSecret_in_memory = unityClientResp.channel.channelSecret;
                                callbackUrl_in_memory  = unityClientResp.channel.callbackUrl;
                                callbackUrl_last       = callbackUrl_in_memory;
                                foreach (ThirdPartySettingsResponse thirdPartySetting in unityClientResp.channel.thirdPartySettings)
                                {
                                    if (thirdPartySetting.appType.Equals(AppStoreOnboardApi.xiaomiAppType, StringComparison.InvariantCultureIgnoreCase))
                                    {
                                        xiaomiAppID.stringValue  = thirdPartySetting.appId;
                                        xiaomiAppKey.stringValue = thirdPartySetting.appKey;
                                        appSecret_in_memory      = thirdPartySetting.appSecret;
                                        appId_last     = xiaomiAppID.stringValue;
                                        appKey_last    = xiaomiAppKey.stringValue;
                                        appSecret_last = appSecret_in_memory;
                                    }
                                }
                                AppStoreOnboardApi.updateRev = unityClientResp.rev;
                                Debug.Log("Unity Client Refreshed. Finished: " + reqStruct.targetStep);
                                AppStoreOnboardApi.loaded = true;
                                isOperationRunning        = false;
                                serializedObject.ApplyModifiedProperties();
                                this.Repaint();
                                AssetDatabase.SaveAssets();
                            }
                            else
                            {
                                // no client found, generate one.
                                if (ownerAuthed)
                                {
                                    UnityClientInfo unityClientInfo = new UnityClientInfo();
                                    string          callbackUrl     = callbackUrl_in_memory;
                                    // read xiaomi from user input
                                    XiaomiSettings xiaomi = new XiaomiSettings();
                                    xiaomi.appId     = xiaomiAppID.stringValue;
                                    xiaomi.appKey    = xiaomiAppKey.stringValue;
                                    xiaomi.appSecret = appSecret_in_memory;
                                    UnityWebRequest     newRequest   = AppStoreOnboardApi.GenerateUnityClient(Application.cloudProjectId, unityClientInfo, xiaomi, callbackUrl);
                                    UnityClientResponse clientResp   = new UnityClientResponse();
                                    ReqStruct           newReqStruct = new ReqStruct();
                                    newReqStruct.request    = newRequest;
                                    newReqStruct.resp       = clientResp;
                                    newReqStruct.targetStep = reqStruct.targetStep;
                                    requestQueue.Enqueue(newReqStruct);
                                }
                                else
                                {
                                    Debug.LogError("Permision denied.");
                                    isOperationRunning = false;
                                }
                            }
                        }
                        else if (resp.GetType() == typeof(UnityClientResponse))
                        {
                            resp = JsonUtility.FromJson <UnityClientResponse> (request.downloadHandler.text);
                            unityClientID.stringValue           = ((UnityClientResponse)resp).client_id;
                            unityClientKey.stringValue          = ((UnityClientResponse)resp).client_secret;
                            unityClientRSAPublicKey.stringValue = ((UnityClientResponse)resp).channel.publicRSAKey;
                            clientSecret_in_memory = ((UnityClientResponse)resp).channel.channelSecret;
                            callbackUrl_in_memory  = ((UnityClientResponse)resp).channel.callbackUrl;
                            callbackUrl_last       = callbackUrl_in_memory;
                            foreach (ThirdPartySettingsResponse thirdPartySetting in ((UnityClientResponse)resp).channel.thirdPartySettings)
                            {
                                if (thirdPartySetting.appType.Equals(AppStoreOnboardApi.xiaomiAppType, StringComparison.InvariantCultureIgnoreCase))
                                {
                                    xiaomiAppID.stringValue  = thirdPartySetting.appId;
                                    xiaomiAppKey.stringValue = thirdPartySetting.appKey;
                                    appSecret_in_memory      = thirdPartySetting.appSecret;
                                    appId_last     = xiaomiAppID.stringValue;
                                    appKey_last    = xiaomiAppKey.stringValue;
                                    appSecret_last = appSecret_in_memory;
                                }
                            }
                            AppStoreOnboardApi.updateRev = ((UnityClientResponse)resp).rev;
                            Debug.Log("Unity Client Refreshed. Finished: " + reqStruct.targetStep);
                            AppStoreOnboardApi.loaded = true;
                            isOperationRunning        = false;
                            serializedObject.ApplyModifiedProperties();
                            this.Repaint();
                            AssetDatabase.SaveAssets();
                        }
                    }
                }
            }
            else
            {
                requestQueue.Enqueue(reqStruct);
            }
        }