public async Task <bool> FastSignUp(SignUpAccount account) { var client = new HttpClient(); var content = new MultipartFormDataContent(); if (account.platform == "DIRECT") { content.Add(new StringContent("NULL", Encoding.UTF8), "first_name"); content.Add(new StringContent("NULL", Encoding.UTF8), "last_name"); content.Add(new StringContent(account.password, Encoding.UTF8), "password"); content.Add(new StringContent(account.email, Encoding.UTF8), "email"); content.Add(new StringContent("NULL", Encoding.UTF8), "social"); content.Add(new StringContent("NULL", Encoding.UTF8), "mobile_access_token"); content.Add(new StringContent("NULL", Encoding.UTF8), "mobile_refresh_token"); content.Add(new StringContent("NULL", Encoding.UTF8), "user_access_token"); content.Add(new StringContent("NULL", Encoding.UTF8), "user_refresh_token"); content.Add(new StringContent("NULL", Encoding.UTF8), "social_id"); } else { content.Add(new StringContent(account.firstName, Encoding.UTF8), "first_name"); content.Add(new StringContent(account.lastName, Encoding.UTF8), "last_name"); content.Add(new StringContent("", Encoding.UTF8), "password"); content.Add(new StringContent(account.email, Encoding.UTF8), "email"); content.Add(new StringContent(account.platform, Encoding.UTF8), "social"); content.Add(new StringContent(account.accessToken, Encoding.UTF8), "mobile_access_token"); content.Add(new StringContent(account.refreshToken, Encoding.UTF8), "mobile_refresh_token"); content.Add(new StringContent("FALSE", Encoding.UTF8), "user_access_token"); content.Add(new StringContent("FALSE", Encoding.UTF8), "user_refresh_token"); content.Add(new StringContent(account.socialID, Encoding.UTF8), "social_id"); } // CONTENT, NAME content.Add(new StringContent("NULL", Encoding.UTF8), "business_uid"); content.Add(new StringContent(GetVersion(), Encoding.UTF8), "referral_source"); content.Add(new StringContent("[]", Encoding.UTF8), "driver_hours"); content.Add(new StringContent("NULL", Encoding.UTF8), "street"); content.Add(new StringContent("NULL", Encoding.UTF8), "unit"); content.Add(new StringContent("NULL", Encoding.UTF8), "city"); content.Add(new StringContent("NULL", Encoding.UTF8), "state"); content.Add(new StringContent("NULL", Encoding.UTF8), "zipcode"); content.Add(new StringContent("NULL", Encoding.UTF8), "latitude"); content.Add(new StringContent("NULL", Encoding.UTF8), "longitude"); content.Add(new StringContent("NULL", Encoding.UTF8), "email"); content.Add(new StringContent("NULL", Encoding.UTF8), "phone"); content.Add(new StringContent("NULL", Encoding.UTF8), "ssn"); content.Add(new StringContent("NULL", Encoding.UTF8), "license_num"); content.Add(new StringContent("NULL", Encoding.UTF8), "license_exp"); content.Add(new StringContent("NULL", Encoding.UTF8), "driver_car_year"); content.Add(new StringContent("NULL", Encoding.UTF8), "driver_car_model"); content.Add(new StringContent("NULL", Encoding.UTF8), "driver_car_make"); content.Add(new StringContent("NULL", Encoding.UTF8), "driver_insurance_carrier"); content.Add(new StringContent("NULL", Encoding.UTF8), "driver_insurance_num"); content.Add(new StringContent("NULL", Encoding.UTF8), "driver_insurance_exp_date"); content.Add(new StringContent("NULL", Encoding.UTF8), "contact_name"); content.Add(new StringContent("NULL", Encoding.UTF8), "contact_phone"); content.Add(new StringContent("NULL", Encoding.UTF8), "contact_relation"); content.Add(new StringContent("NULL", Encoding.UTF8), "bank_acc_info"); content.Add(new StringContent("NULL", Encoding.UTF8), "bank_routing_info"); var array = new byte[0]; var temp = new ByteArrayContent(array); // CONTENT, NAME, FILENAME content.Add(temp, "driver_insurance_picture", "product_image.png"); var request = new HttpRequestMessage(); request.RequestUri = new Uri(Constant.SignUpUrl); request.Method = HttpMethod.Post; request.Content = content; var response = await client.SendAsync(request); if (response.IsSuccessStatusCode) { var contentString = await response.Content.ReadAsStringAsync(); var data = JsonConvert.DeserializeObject <FastSignUpAccount>(contentString); Debug.WriteLine("contentString: " + contentString); DateTime today = DateTime.Now; DateTime expDate = today.AddDays(Constant.days); user = new User(); user.id = data.result.driver_uid; user.sessionTime = expDate; user.platform = account.platform; user.email = ""; user.socialId = ""; user.route_id = ""; return(true); } return(false); }
// This function evaluates direct user's userType based on role and whether or not // their profile was updated succesfully. (Overloading) //async Task<UserTypeEvaluation> EvaluateUserType(string role, string password) //{ // UserTypeEvaluation userType = new UserTypeEvaluation(); // try // { // if (role == "CUSTOMER" || role == "ADMIN") // { // userType.role = "CUSTOMER"; // userType.statusCode = true; // } // else if (role == "GUEST") // { // var didProfileUpdatedSucessfully = await UpdateUserProfile(password); // if (didProfileUpdatedSucessfully) // { // userType.role = "CUSTOMER"; // userType.statusCode = true; // } // else // { // userType.role = "GUEST"; // userType.statusCode = false; // } // } // } // catch // { // } // return userType; //} // This function evaluates social media user's userType based on role and whether or not // their profile was updated succesfully. (Overloading) //async Task<UserTypeEvaluation> EvaluateUserType(string role, string mobile_access_token, string mobile_refresh_token, string social_id, string platform) //{ // UserTypeEvaluation userType = new UserTypeEvaluation(); // try // { // if (role == "CUSTOMER" || role == "ADMIN") // { // userType.role = "CUSTOMER"; // userType.statusCode = true; // } // else if (role == "GUEST") // { // var didProfileUpdatedSucessfully = await UpdateUserProfile(mobile_access_token, mobile_refresh_token, social_id, platform); // if (didProfileUpdatedSucessfully) // { // userType.role = "CUSTOMER"; // userType.statusCode = true; // } // else // { // userType.role = "GUEST"; // userType.statusCode = false; // } // } // } // catch // { // } // return userType; //} // This function updates direct user's role from GUEST to CUSTOMER. (Overloading) //async Task<bool> UpdateUserProfile(string password) //{ // bool result = false; // try // { // var clientSignUp = new SignUp(); // var content = clientSignUp.UpdateDirectUser(user, password); // result = await SignUp.SignUpNewUser(content); // } // catch // { // Debug.Write("ERROR UPDATING DIRECT USER'S PROFILE FROM GUEST TO CUSTOMER"); // } // return result; //} // This function updates social media user's role from GUEST to CUSTOMER. (Overloading) //async Task<bool> UpdateUserProfile(string mobile_access_token, string mobile_refresh_token, string social_id, string platform) //{ // bool result = false; // try // { // var clientSignUp = new SignUp(); // var content = clientSignUp.UpdateSocialUser(user, mobile_access_token, mobile_refresh_token, social_id, platform); // result = await SignUp.SignUpNewUser(content); // } // catch // { // Debug.Write("ERROR UPDATING SOCIAL MEDIA USER'S PROFILE FROM GUEST TO CUSTOMER"); // } // return result; //} // EVALUATION FUNTIONS FOR DIRECT AND SOCIAL MEDIA ____________________ // NOTIFICATION FUNCTION ______________________________________________ // This function send GUID to database. //async Task<bool> SetUserRemoteNotification() //{ // bool result = false; // try // { // deviceId = Preferences.Get("guid", null); // if (deviceId != null) // { // var client = new HttpClient(); // NotificationPost notificationPost = new NotificationPost(); // notificationPost.uid = user.getUserID(); // notificationPost.guid = deviceId.Substring(5); // user.setUserDeviceID(deviceId.Substring(5)); // notificationPost.notification = "TRUE"; // var notificationSerializedObject = JsonConvert.SerializeObject(notificationPost); // var notificationContent = new StringContent(notificationSerializedObject, Encoding.UTF8, "application/json"); // var clientResponse = await client.PostAsync(Constant.NotificationsUrl, notificationContent); // if (clientResponse.IsSuccessStatusCode) // { // result = true; // Debug.WriteLine("GUID WAS WRITTEN SUCCESFULLY WERE SET SUCESSFULLY"); // } // else // { // Debug.WriteLine("ERROR SETTING GUID FOR NOTIFICATIONS"); // } // } // } // catch // { // } // return result; //} // NOTIFICATION FUNCTION ______________________________________________ // SOCIAL MEDIA VERIFICATION FUNCTION__________________________________ // This function verifies if credentails exist and whether or not user is // authenticated by our system. (Overloading) public async Task <string> VerifyUserCredentials(string accessToken = "", string refreshToken = "", AuthenticatorCompletedEventArgs googleAccount = null, AppleAccount appleCredentials = null, string platform = "") { var isUserVerified = ""; try { string _accessToken = accessToken; string _refreshToken = refreshToken; var client = new HttpClient(); var socialLogInPost = new SocialLogInPost(); var googleData = new GoogleResponse(); var facebookData = new FacebookResponse(); if (platform == "GOOGLE") { var request = new OAuth2Request("GET", new Uri(Constant.GoogleUserInfoUrl), null, googleAccount.Account); var GoogleResponse = await request.GetResponseAsync(); var googelUserData = GoogleResponse.GetResponseText(); googleData = JsonConvert.DeserializeObject <GoogleResponse>(googelUserData); socialLogInPost.email = googleData.email; socialLogInPost.social_id = googleData.id; //Debug.WriteLine("IMAGE: " + googleData.picture); //user.setUserImage(googleData.picture); _accessToken = accessToken; _refreshToken = refreshToken; } else if (platform == "FACEBOOK") { var facebookResponse = client.GetStringAsync(Constant.FacebookUserInfoUrl + accessToken); var facebookUserData = facebookResponse.Result; Debug.WriteLine("FACEBOOK DATA: " + facebookUserData); facebookData = JsonConvert.DeserializeObject <FacebookResponse>(facebookUserData); socialLogInPost.email = facebookData.email; socialLogInPost.social_id = facebookData.id; _accessToken = accessToken; _refreshToken = refreshToken; } else if (platform == "APPLE") { socialLogInPost.email = appleCredentials.Email; socialLogInPost.social_id = appleCredentials.UserId; _accessToken = appleCredentials.Token; _refreshToken = appleCredentials.Token; } socialLogInPost.password = ""; socialLogInPost.signup_platform = platform; var socialLogInPostSerialized = JsonConvert.SerializeObject(socialLogInPost); var postContent = new StringContent(socialLogInPostSerialized, Encoding.UTF8, "application/json"); var RDSResponse = await client.PostAsync(Constant.LogInUrl, postContent); var responseContent = await RDSResponse.Content.ReadAsStringAsync(); var authetication = JsonConvert.DeserializeObject <RDSAuthentication>(responseContent); if (RDSResponse.IsSuccessStatusCode) { if (responseContent != null) { if (authetication.code.ToString() == Constant.EmailNotFound) { // need to sign up userToSignUp = new SignUpAccount(); if (platform == "GOOGLE") { userToSignUp.socialID = googleData.id; userToSignUp.email = googleData.email; userToSignUp.firstName = googleData.given_name; userToSignUp.lastName = googleData.family_name; userToSignUp.accessToken = _accessToken; userToSignUp.refreshToken = _refreshToken; userToSignUp.platform = platform; } else if (platform == "FACEBOOK") { userToSignUp.socialID = facebookData.id; userToSignUp.email = facebookData.email; userToSignUp.firstName = facebookData.name; userToSignUp.accessToken = _accessToken; userToSignUp.refreshToken = _refreshToken; userToSignUp.platform = platform; } else if (platform == "APPLE") { userToSignUp.socialID = appleCredentials.UserId; userToSignUp.email = appleCredentials.Email; userToSignUp.firstName = appleCredentials.Name; userToSignUp.accessToken = _accessToken; userToSignUp.refreshToken = _refreshToken; userToSignUp.platform = platform; } isUserVerified = "USER NEEDS TO SIGN UP"; } if (authetication.code.ToString() == Constant.AutheticatedSuccesful) { try { DateTime today = DateTime.Now; DateTime expDate = today.AddDays(Constant.days); user = new User(); user.id = authetication.result[0].driver_uid; user.sessionTime = expDate; user.platform = platform; user.email = ""; user.socialId = ""; user.route_id = ""; var statusUpdatingTokens = await UpdateAccessRefreshToken(user.id, accessToken, refreshToken); isUserVerified = EvaluteUserUpdates(statusUpdatingTokens); SaveUser(user); } catch (Exception second) { Debug.WriteLine(second.Message); } } if (authetication.code.ToString() == Constant.ErrorPlatform) { //var RDSCode = JsonConvert.DeserializeObject<RDSLogInMessage>(responseContent); isUserVerified = "WRONG SOCIAL MEDIA TO SIGN IN"; } if (authetication.code.ToString() == Constant.ErrorUserDirectLogIn) { isUserVerified = "SIGN IN DIRECTLY"; } } } } catch (Exception errorVerifyUserCredentials) { //var client = new Diagnostic(); //client.parseException(errorVerifyUserCredentials.ToString(), user); Debug.WriteLine("ERROR IN 'errorVerifyUserCredentials' FUNCTION"); isUserVerified = "ERROR"; } return(isUserVerified); }
// DIRECT VERIFICATION FUNCTIONS_______________________________________ // This function retrives direct user's account salt credentials. public async Task <AccountSalt> RetrieveAccountSalt(string userEmail) { AccountSalt userInformation = null; try { SaltPost saltPost = new SaltPost(); saltPost.email = userEmail; var saltPostSerilizedObject = JsonConvert.SerializeObject(saltPost); var saltPostContent = new StringContent(saltPostSerilizedObject, Encoding.UTF8, "application/json"); var client = new HttpClient(); var DRSResponse = await client.PostAsync(Constant.AccountSaltUrl, saltPostContent); var DRSMessage = await DRSResponse.Content.ReadAsStringAsync(); if (DRSResponse.IsSuccessStatusCode) { var result = await DRSResponse.Content.ReadAsStringAsync(); AcountSaltCredentials data = new AcountSaltCredentials(); data = JsonConvert.DeserializeObject <AcountSaltCredentials>(result); if (DRSMessage.Contains(Constant.UseSocialMediaLogin)) { userInformation = new AccountSalt { password_algorithm = null, password_salt = null, message = data.message == null ? "" : data.message }; } else if (DRSMessage.Contains(Constant.EmailNotFound)) { userToSignUp = new SignUpAccount(); userToSignUp.email = userEmail.ToLower().Trim(); userToSignUp.platform = "DIRECT"; userInformation = new AccountSalt { password_algorithm = null, password_salt = null, message = "USER NEEDS TO SIGN UP" }; } else { userInformation = new AccountSalt { password_algorithm = data.result[0].password_algorithm, password_salt = data.result[0].password_salt, message = null }; } } } catch (Exception errorRetrieveAccountSalt) { //var client = new Diagnostic(); //client.parseException(errorRetrieveAccountSalt.ToString(), user); Debug.WriteLine("ERROR "); } return(userInformation); }
// This function verifies if credentails exist and whether or not user is // authenticated by our system. (Overloading) public async Task <string> VerifyUserCredentials(string userEmail, string userPassword, AccountSalt accountSalt) { string isUserVerified = ""; try { SHA512 sHA512 = new SHA512Managed(); var client = new HttpClient(); byte[] data = sHA512.ComputeHash(Encoding.UTF8.GetBytes(userPassword + accountSalt.password_salt)); string hashedPassword = BitConverter.ToString(data).Replace("-", string.Empty).ToLower(); LogInPost loginPostContent = new LogInPost(); loginPostContent.email = userEmail; loginPostContent.password = hashedPassword; loginPostContent.social_id = ""; loginPostContent.signup_platform = ""; string loginPostContentJson = JsonConvert.SerializeObject(loginPostContent); var httpContent = new StringContent(loginPostContentJson, Encoding.UTF8, "application/json"); var response = await client.PostAsync(Constant.LogInUrl, httpContent); if (response.IsSuccessStatusCode) { var responseContent = await response.Content.ReadAsStringAsync(); var authetication = JsonConvert.DeserializeObject <RDSAuthentication>(responseContent); if (authetication.code.ToString() == Constant.EmailNotFound) { userToSignUp = new SignUpAccount(); userToSignUp.email = userEmail.ToLower().Trim(); userToSignUp.password = userPassword.Trim(); userToSignUp.platform = "DIRECT"; isUserVerified = "USER NEEDS TO SIGN UP"; } else if (authetication.code.ToString() == Constant.AutheticatedSuccesful) { DateTime today = DateTime.Now; DateTime expDate = today.AddDays(Constant.days); user = new User(); user.id = authetication.result[0].driver_uid; user.sessionTime = expDate; user.platform = "DIRECT"; user.email = ""; user.socialId = ""; user.route_id = ""; //var notificationStatus = await SetUserRemoteNotification(); //isUserVerified = EvaluteUserUpdates(notificationStatus); isUserVerified = "SUCCESSFUL:0"; SaveUser(user); } else if (authetication.code.ToString() == Constant.ErrorPlatform) { //var RDSCode = JsonConvert.DeserializeObject<RDSLogInMessage>(responseContent); isUserVerified = "WRONG SOCIAL MEDIA TO SIGN IN"; } else if (authetication.code.ToString() == Constant.ErrorUserDirectLogIn) { isUserVerified = "WRONG DIRECT PASSWORD"; } } } catch (Exception errorLogInUser) { //var client = new Diagnostic(); //client.parseException(errorLogInUser.ToString(), user); Debug.WriteLine("ERROR THE 'errorLogInUser' FUNCTION: " + errorLogInUser.Message); } return(isUserVerified); }