void mProfileTracker_mOnProfileChanged(object sender, OnProfileChangedEventArgs e) { LoginManager.Instance.LogInWithReadPermissions(this, new List <string> { "user_friends", "public_profile" }); if (e.mProfile != null) { try { var sc = new SocialLoginData(); sc.scFirstName = e.mProfile.FirstName; sc.scLastName = e.mProfile.LastName; sc.scUserName = e.mProfile.FirstName + e.mProfile.LastName; sc.scSocialId = e.mProfile.Id; facebookpicture = "http://graph.facebook.com/" + e.mProfile.Id + "/picture?type=large"; sc.scProfileImgUrl = facebookpicture; sc.scEmail = email ?? ""; sc.scSource = "facebook"; sc.scAccessUrl = "http://facebook.com/profile.php?id=" + e.mProfile.Id; sc.scSocialOauthToken = AccessToken.CurrentAccessToken.Token; sc.scAccount = AccessToken.CurrentAccessToken.UserId; GraphRequest request = GraphRequest.NewMeRequest(AccessToken.CurrentAccessToken, this); Bundle parameters = new Bundle(); parameters.PutString("fields", "id,name,email,picture"); request.Parameters = parameters; request.ExecuteAsync(); StartRegistration(sc); } catch (Java.Lang.Exception ex) { } } }
#endregion LogIn with Email public void FacebookLoginProcess(LoginButtonCompletedEventArgs e) { if (e.Error != null) { Console.WriteLine(e.Error.ToString()); new UIAlertView("Facebook", "We were not able to authenticate you with Facebook. Please login again.", null, "OK", null) .Show(); } else if (e.Result.IsCancelled) { Console.WriteLine("Result was cancelled"); new UIAlertView("Facebook", "You cancelled the Facebook login process. Please login again.", null, "OK", null).Show(); } else if (!e.Result.GrantedPermissions.ToString().Contains("email")) { // Check that we have email as a permission, otherwise show that we can't signup Console.WriteLine("Email permission not found"); new UIAlertView("Facebook", "Email permission is required to sign in, Please login again.", null, "OK", null).Show(); } else { var meRequest = new GraphRequest("/me", new NSDictionary("fields", "first_name,last_name,name,email,picture"), "GET"); var requestConnection = new GraphRequestConnection(); requestConnection.AddRequest(meRequest, (connection, meResult, meError) => { var client = new WebClient(); if (meError != null) { Console.WriteLine(meError.ToString()); new UIAlertView("Facebook", "Unable to login to facebook.", null, "OK", null).Show(); return; } var user = meResult as NSDictionary; var sc = new SocialLoginData(); sc.scFirstName = user.ValueForKey(new NSString("first_name")).Description; sc.scLastName = user.ValueForKey(new NSString("last_name")).Description; sc.scUserName = user.ValueForKey(new NSString("name")).Description; sc.scSocialId = user.ValueForKey(new NSString("id")).Description; sc.scEmail = user.ValueForKey(new NSString("email")).Description; sc.scProfileImgUrl = ""; //user.ValueForKey(new NSString("picture")).Description; sc.scSource = "facebook"; sc.scAccessUrl = "http://facebook.com/profile.php?id=" + user.ValueForKey(new NSString("id")).Description; sc.scSocialOauthToken = AccessToken.CurrentAccessToken.TokenString; sc.scAccount = AccessToken.CurrentAccessToken.TokenString; StartRegistration(sc); }); requestConnection.Start(); } } public async void StartRegistration(SocialLoginData SocialData) { InpowerResult Result = null; UserProfile userProfile = new UserProfile(); try { string isscEmail = ""; if (SocialData.scEmail != "" || SocialData.scEmail != null) { isscEmail = SocialData.scEmail; }else{isscEmail = SocialData.scFirstName + SocialData.scLastName + SocialData.scSocialId + "@InPower.com";} Result = await new AccountService().Registration(new UserRegisterRequestViewModel { FirstName = SocialData.scFirstName, LastName = SocialData.scLastName, Email = isscEmail , Password = "******" }, GlobalConstant.AccountUrls.RegisterServiceUrl); var modelReporeg = JsonConvert.DeserializeObject<UserRegisterResponseViewModel>(Result.Response.ToString()); var ResultToken = await new AccountService().AccessToken(new TokenRequestViewModel { UserName = modelReporeg.Email, password = modelReporeg.Password, grant_type = "password" }); if (Result.Message == "Detail Successfully Updated") { ContinuetoMainScreen(modelReporeg.UserId.ToString(), modelReporeg.Password, ResultToken.access_token, modelReporeg.Email, modelReporeg.AWSAccessKey,modelReporeg.AWSSecretKey); } else { var token = AccessToken.CurrentAccessToken != null; if (ResultToken != null) { userProfile = new UserProfile { ProfileImageUrl = "",//respose.JSONObject.GetJSONObject("picture").GetJSONObject("data").GetString("url"), UserId = modelReporeg.UserId, FirstName = modelReporeg.FirstName, LastName = modelReporeg.LastName, Email = modelReporeg.Email, Password = modelReporeg.Password, AccessToken = ResultToken.access_token, isActive = modelReporeg.isActive, isShoutout = modelReporeg.isShoutout }; //var pictureUrl = respose.JSONObject.GetJSONObject("picture").GetJSONObject("data").GetString("url"); //var pictureData = client.DownloadData(pictureUrl); UserProfileRepository.SaveUserProfile(userProfile); CommonHelper.SetUserPreferences(modelReporeg.UserId.ToString(), modelReporeg.Password.ToLower(), ResultToken.access_token, modelReporeg.Email, modelReporeg.AWSAccessKey, modelReporeg.AWSSecretKey); GlobalConstant.AccessToken = ResultToken.access_token; new UIAlertView("Facebook Login", Result.Message, null, "OK", null).Show(); this.DismissViewController(true,null); InvokeOnMainThread(delegate { UIStoryboard storyboard = this.Storyboard; PleaseComplateYourProfileTableViewController viewController = (PleaseComplateYourProfileTableViewController) storyboard.InstantiateViewController("PleaseComplateYourProfileTableViewController"); viewController.userProfile = userProfile; this.PresentViewController(viewController, true, null); }); } else { new UIAlertView("Facebook Login", Result.Message, null, "OK", null).Show(); return; } } } catch (Exception ex) { Crashes.TrackError(ex); new UIAlertView("Facebook Login", ex.Message, null, "OK", null).Show(); return; } }
#endregion LogIn with Email public void FacebookLoginProcess(LoginButtonCompletedEventArgs e) { if (e.Error != null) { Console.WriteLine(e.Error.ToString()); new UIAlertView("Facebook", "We were not able to authenticate you with Facebook. Please login again.", null, "OK", null) .Show(); } else if (e.Result.IsCancelled) { Console.WriteLine("Result was cancelled"); new UIAlertView("Facebook", "You cancelled the Facebook login process. Please login again.", null, "OK", null).Show(); } else if (!e.Result.GrantedPermissions.ToString().Contains("email")) { // Check that we have email as a permission, otherwise show that we can't signup Console.WriteLine("Email permission not found"); new UIAlertView("Facebook", "Email permission is required to sign in, Please login again.", null, "OK", null).Show(); } else { var meRequest = new GraphRequest("/me", new NSDictionary("fields", "first_name,last_name,name,email,picture"), "GET"); var requestConnection = new GraphRequestConnection(); requestConnection.AddRequest(meRequest, (connection, meResult, meError) => { var client = new WebClient(); if (meError != null) { Console.WriteLine(meError.ToString()); new UIAlertView("Facebook", "Unable to login to facebook.", null, "OK", null).Show(); return; } var user = meResult as NSDictionary; var sc = new SocialLoginData(); sc.scFirstName = user.ValueForKey(new NSString("first_name")).Description; sc.scLastName = user.ValueForKey(new NSString("last_name")).Description; sc.scUserName = user.ValueForKey(new NSString("name")).Description; sc.scSocialId = user.ValueForKey(new NSString("id")).Description; sc.scEmail = user.ValueForKey(new NSString("email")).Description; sc.scProfileImgUrl = ""; //user.ValueForKey(new NSString("picture")).Description; sc.scSource = "facebook"; sc.scAccessUrl = "http://facebook.com/profile.php?id=" + user.ValueForKey(new NSString("id")).Description; sc.scSocialOauthToken = AccessToken.CurrentAccessToken.TokenString; sc.scAccount = AccessToken.CurrentAccessToken.TokenString; StartRegistration(sc); }); requestConnection.Start(); } } public async void StartRegistration(SocialLoginData SocialData) { InpowerResult Result = null; UserProfile userProfile = new UserProfile(); try { string isscEmail = ""; if (SocialData.scEmail != "" || SocialData.scEmail != null) { isscEmail = SocialData.scEmail; }else{isscEmail = SocialData.scFirstName + SocialData.scLastName + SocialData.scSocialId + "@InPower.com";} Result = await new AccountService().Registration(new UserRegisterRequestViewModel { FirstName = SocialData.scFirstName, LastName = SocialData.scLastName, Email = isscEmail , Password = "******" }, GlobalConstant.AccountUrls.RegisterServiceUrl); var modelReporeg = JsonConvert.DeserializeObject<UserRegisterResponseViewModel>(Result.Response.ToString()); var ResultToken = await new AccountService().AccessToken(new TokenRequestViewModel { UserName = modelReporeg.Email, password = modelReporeg.Password, grant_type = "password" }); if (Result.Message == "Detail Successfully Updated") { ContinuetoMainScreen(modelReporeg.UserId.ToString(), modelReporeg.Password, ResultToken.access_token, modelReporeg.Email, modelReporeg.AWSAccessKey,modelReporeg.AWSSecretKey); } else { var token = AccessToken.CurrentAccessToken != null; if (ResultToken != null) {
public async Task StartRegistration(SocialLoginData SocialData) { InpowerResult Result = null; try { Result = await new AccountService().Registration(new UserRegisterRequestViewModel { FirstName = SocialData.scFirstName, LastName = SocialData.scLastName, Email = SocialData.scFirstName + SocialData.scLastName + SocialData.scSocialId + "@InPower.com", Password = "******" }, GlobalConstant.AccountUrls.RegisterServiceUrl); var modelReporeg = JsonConvert.DeserializeObject <UserRegisterResponseViewModel>(Result.Response.ToString()); var ResultToken = await new AccountService().AccessToken(new TokenRequestViewModel { UserName = modelReporeg.Email, password = modelReporeg.Password, grant_type = "password" }); if (Result.Message == "Detail Successfully Updated") { var token = AccessToken.CurrentAccessToken != null; SocialData.scSocialOauthToken = AccessToken.CurrentAccessToken?.Token; UserProfile loginUserDetails = UserProfileRepository.GetUserProfile(CommonHelper.GetUserId()); var intent = new Intent(this, typeof(MainActivity)); intent.AddFlags(ActivityFlags.SingleTop); StartActivity(intent); CommonHelper.SetUserPreferences(modelReporeg.UserId.ToString(), modelReporeg.Password.ToLower(), ResultToken.access_token, modelReporeg.Email, modelReporeg.AWSAccessKey, modelReporeg.AWSSecretKey, null, null); GlobalConstant.AccessToken = ResultToken.access_token; this.Finish(); } else { var token = AccessToken.CurrentAccessToken != null; if (ResultToken != null) { if (token) { SocialData.scSocialOauthToken = AccessToken.CurrentAccessToken?.Token; UserProfile userProfile; userProfile = new UserProfile { Email = email ?? "", ProfileImageUrl = facebookpicture ?? "", UserId = modelReporeg.UserId, FirstName = modelReporeg.FirstName, LastName = modelReporeg.LastName, Password = modelReporeg.Password, AccessToken = ResultToken.access_token, isActive = modelReporeg.isActive, isShoutout = modelReporeg.isShoutout }; UserProfileRepository.SaveUserProfile(userProfile); CommonHelper.SetUserPreferences(modelReporeg.UserId.ToString(), modelReporeg.Password.ToLower(), ResultToken.access_token, userProfile.Email, modelReporeg.AWSAccessKey, modelReporeg.AWSSecretKey, null, null); GlobalConstant.AccessToken = ResultToken.access_token; Toast.MakeText(this, Result.Message, ToastLength.Short).Show(); // CommonHelper.DismissProgressBar(this); // this.Finish(); //var UserprofileRepo = UserProfileRepository.GetUserProfile(CommonHelper.GetUserId()); //if (modelReporeg.UserId==) this.Finish(); var intent = new Intent(this, typeof(ComplateYourProfileActivity)); intent.PutExtra("UserProfile", JsonConvert.SerializeObject(userProfile)); intent.AddFlags(ActivityFlags.SingleTop); StartActivity(intent); } } else { // CommonHelper.DismissProgressBar(this); Toast.MakeText(this, Result.Message, ToastLength.Short).Show(); return; } } } catch (Exception ex) { // CommonHelper.DismissProgressBar(this); string ErrorMsg = ex.ToString(); Toast.MakeText(this, ErrorMsg, ToastLength.Long).Show(); } }
public ResultObj <tbl_Customer_Master> SocialLogin(SocialLoginData data) { var connectionString = ConfigurationManager.ConnectionStrings["CharityManagement"].ConnectionString; try { sqlConnection = new SqlConnection(connectionString); string command = "select * from [dbo].[tbl_Customer_Master] where ( cust_FacebookID = '" + data.SocialID + "' or cust_GoogleID = '" + data.SocialID + "' or cust_TwitterID ='" + data.SocialID + "') and (cust_Email = '" + data.Email + "' " + "and cust_MobileNo = '" + data.MobileNo + "')"; sqlCommand = new SqlCommand(command, sqlConnection); sqlConnection.Open(); sqlDataReader = sqlCommand.ExecuteReader(); if (sqlDataReader.HasRows) { while (sqlDataReader.Read()) { customerObject = new tbl_Customer_Master(); customerObject.cust_Id = (Guid)sqlDataReader["cust_Id"]; if (!string.IsNullOrEmpty(sqlDataReader["cust_FirstName"].ToString())) { customerObject.cust_FirstName = sqlDataReader["cust_FirstName"].ToString(); } if (!string.IsNullOrEmpty(sqlDataReader["cust_LastName"].ToString())) { customerObject.cust_LastName = sqlDataReader["cust_LastName"].ToString(); } if (!string.IsNullOrEmpty(sqlDataReader["cust_MobileNo"].ToString())) { customerObject.cust_MobileNo = sqlDataReader["cust_MobileNo"].ToString(); } if (!string.IsNullOrEmpty(sqlDataReader["cust_FacebookID"].ToString())) { customerObject.cust_FacebookID = sqlDataReader["cust_FacebookID"].ToString(); } if (!string.IsNullOrEmpty(sqlDataReader["cust_GoogleID"].ToString())) { customerObject.cust_GoogleID = sqlDataReader["cust_GoogleID"].ToString(); } if (!string.IsNullOrEmpty(sqlDataReader["cust_TwitterID"].ToString())) { customerObject.cust_TwitterID = sqlDataReader["cust_TwitterID"].ToString(); } if (!string.IsNullOrEmpty(sqlDataReader["cust_IMEI"].ToString())) { customerObject.cust_IMEI = sqlDataReader["cust_IMEI"].ToString(); } if (sqlDataReader["cust_IsActive"] != DBNull.Value) { customerObject.cust_IsActive = Convert.ToInt16(sqlDataReader["cust_IsActive"]); } if (!string.IsNullOrEmpty(sqlDataReader["cust_Manifacturer"].ToString())) { customerObject.cust_Manifacturer = sqlDataReader["cust_Manifacturer"].ToString(); } if (sqlDataReader["cust_Modifiedby"] != DBNull.Value) { customerObject.cust_Modifiedby = (Guid)sqlDataReader["cust_Modifiedby"]; } if (sqlDataReader["cust_ModifiedDate"] != DBNull.Value) { customerObject.cust_ModifiedDate = Convert.ToDateTime(sqlDataReader["cust_ModifiedDate"]); } if (!string.IsNullOrEmpty(sqlDataReader["cust_ProfileImage"].ToString())) { customerObject.cust_ProfileImage = sqlDataReader["cust_ProfileImage"].ToString(); } if (!string.IsNullOrEmpty(sqlDataReader["cust_Remarks"].ToString())) { customerObject.cust_Remarks = sqlDataReader["cust_Remarks"].ToString(); } sqlDataReader.NextResult(); } _resultObj.Status = true; _resultObj.Message = "User Logged In Sucessfully"; _resultObj.Data = customerObject; return(_resultObj); } else { return(new ResultObj <tbl_Customer_Master>(false, "Invalid Username or Password!", null, 0, 0)); } } catch (Exception ex) { LogMessage.WriteLog("At Customer Repo UserInfo Method" + ex.Message.ToString()); return(new ResultObj <tbl_Customer_Master>(false, ex.Message.ToString(), null, 0, 0)); } finally { sqlDataReader.Close(); sqlConnection.Close(); } }
public ResultObj <tbl_Customer_Master> SocialLogin([FromBody] SocialLoginData data) { return(_repoObj.SocialLogin(data)); }