public IActionResult GetGplusProfilesOnly(long groupId) { var lstGplusAcc = new List <Googleplusaccounts>(); try { var dbr = new DatabaseRepository(_logger, _appEnv); var lstGrpProfiles = GroupProfilesRepository.GetAllGroupProfiles(groupId, _redisCache, dbr) .Where(t => t.profileType == SocialProfileType.GPlus); lstGplusAcc.AddRange( from item in lstGrpProfiles select GplusRepository.getGPlusAccount(item.profileId, _redisCache, dbr) into gPlusAcc let userdata = dbr.Single <User>(t => t.Id == gPlusAcc.UserId) where gPlusAcc != null && userdata.EmailId != gPlusAcc.EmailId select gPlusAcc); return(Ok(lstGplusAcc)); } catch (Exception) { return(Ok(lstGplusAcc)); } }
public IActionResult GetPrimaryGoogleAcc(long userId, long groupId) { var userGplusAcc = new Googleplusaccounts(); try { var dbr = new DatabaseRepository(_logger, _appEnv); var lstGrpProfiles = GroupProfilesRepository.GetAllGroupProfiles(groupId, _redisCache, dbr); lstGrpProfiles = lstGrpProfiles.Where(t => t.profileType == SocialProfileType.GPlus).ToList(); foreach (var item in lstGrpProfiles) { var gPlusAcc = GplusRepository.getGPlusAccount(item.profileId, _redisCache, dbr); var userdata = dbr.Single <User>(t => t.Id == gPlusAcc.UserId); if (gPlusAcc != null && userdata.EmailId == gPlusAcc.EmailId) { userGplusAcc = gPlusAcc; } } } catch (Exception e) { Console.WriteLine(e); } return(Ok(userGplusAcc)); }
public IActionResult AddGoogleAccountPhone(string refreshToken, string accessToken, long groupId, long userId) { var ret = string.Empty; var objRefresh = string.Empty; var dbr = new DatabaseRepository(_logger, _appEnv); var ObjoAuthTokenGPlus = new oAuthTokenGPlus(_appSettings.GoogleConsumerKey, _appSettings.GoogleConsumerSecret, _appSettings.GoogleRedirectUri); var objToken = new oAuthToken(_appSettings.GoogleConsumerKey, _appSettings.GoogleConsumerSecret, _appSettings.GoogleRedirectUri); var userinfo = new JObject(); try { var user = objToken.GetUserInfo("self", accessToken); //_logger.LogInformation(user); userinfo = JObject.Parse(JArray.Parse(user)[0].ToString()); var people = objToken.GetPeopleInfo("self", accessToken, Convert.ToString(userinfo["id"])); userinfo = JObject.Parse(JArray.Parse(people)[0].ToString()); } catch (Exception ex) { _logger.LogInformation(ex.Message); _logger.LogError(ex.StackTrace); ret = "Access Token Not Found"; return(Ok(ret)); } var gplusAcc = GplusRepository.getGPlusAccount(Convert.ToString(userinfo["id"]), _redisCache, dbr); if (gplusAcc != null && gplusAcc.IsActive) { if (gplusAcc.UserId == userId) { return(BadRequest("GPlus account already added by you.")); } return(BadRequest("GPlus account added by other user.")); } var ngrp = dbr.Find <Groups>(t => t.adminId == userId && t.id == groupId).FirstOrDefault(); if (ngrp == null) { return(Ok("group not exist")); } // Adding GPlus Profile var x = GplusRepository.AddGplusAccount(userinfo, dbr, userId, ngrp.id, accessToken, refreshToken, _redisCache, _appSettings, _logger); if (x == 1) { return(Ok("Gplus Account Added Successfully")); } return(BadRequest("Issues while adding account")); }
public IActionResult GetAllGplusProfiles(long groupId) { var lstGplusAcc = new List <Googleplusaccounts>(); try { var dbr = new DatabaseRepository(_logger, _appEnv); var lstGrpProfiles = GroupProfilesRepository.GetAllGroupProfiles(groupId, _redisCache, dbr); foreach (var item in lstGrpProfiles.Where(t => t.profileType == SocialProfileType.GPlus)) { var gPlusAcc = GplusRepository.getGPlusAccount(item.profileId, _redisCache, dbr); if (gPlusAcc != null) { lstGplusAcc.Add(gPlusAcc); } } } catch (Exception e) { Console.WriteLine(e); } return(Ok(lstGplusAcc)); }
public IActionResult RecGoogleAccount(string code, long userId) { var ret = string.Empty; var objRefresh = string.Empty; var refreshToken = string.Empty; var access_token = string.Empty; var dbr = new DatabaseRepository(_logger, _appEnv); var ObjoAuthTokenGPlus = new oAuthTokenGPlus(_appSettings.GoogleConsumerKey, _appSettings.GoogleConsumerSecret, _appSettings.GoogleRedirectUri); var objToken = new oAuthToken(_appSettings.GoogleConsumerKey, _appSettings.GoogleConsumerSecret, _appSettings.GoogleRedirectUri); var userinfo = new JObject(); try { objRefresh = ObjoAuthTokenGPlus.GetRefreshToken(code); var objaccesstoken = JObject.Parse(objRefresh); _logger.LogInformation(objaccesstoken.ToString()); try { refreshToken = objaccesstoken["refresh_token"].ToString(); } catch { } access_token = objaccesstoken["access_token"].ToString(); var user = objToken.GetUserInfo("self", access_token); //_logger.LogInformation(user); userinfo = JObject.Parse(JArray.Parse(user)[0].ToString()); var people = objToken.GetPeopleInfo("self", access_token, Convert.ToString(userinfo["id"])); userinfo = JObject.Parse(JArray.Parse(people)[0].ToString()); } catch (Exception ex) { //access_token = objaccesstoken["access_token"].ToString(); //ObjoAuthTokenGPlus.RevokeToken(access_token); _logger.LogInformation(ex.Message); _logger.LogError(ex.StackTrace); ret = "Access Token Not Found"; return(Ok(ret)); } var gplusAcc = GplusRepository.getGPlusAccount(Convert.ToString(userinfo["id"]), _redisCache, dbr); if (gplusAcc != null && gplusAcc.IsActive) { if (gplusAcc.UserId == userId) { } } // Adding GPlus Profile var x = GplusRepository.ReconnectGplusAccount(userinfo, dbr, userId, access_token, refreshToken, _redisCache, _appSettings, _logger); if (x == 1) { return(Ok("Gplus Account Reconnect Successfully")); } return(BadRequest("Issues while adding account")); }
public IActionResult GoogleLoginPhone(string refreshToken, string accessToken, SBAccountType accType) { var ret = string.Empty; var objRefresh = string.Empty; var ObjoAuthTokenGPlus = new oAuthTokenGPlus(_appSettings.GoogleConsumerKey, _appSettings.GoogleConsumerSecret, _appSettings.GoogleRedirectUri); var objToken = new oAuthToken(_appSettings.GoogleConsumerKey, _appSettings.GoogleConsumerSecret, _appSettings.GoogleRedirectUri); var userinfo = new JObject(); try { var user = objToken.GetUserInfo("self", accessToken); _logger.LogInformation(user); userinfo = JObject.Parse(JArray.Parse(user)[0].ToString()); } catch (Exception ex) { _logger.LogInformation(ex.Message); _logger.LogError(ex.StackTrace); ret = "Access Token Not Found"; return(Ok(ret)); } var EmailId = string.Empty; try { EmailId = Convert.ToString(userinfo["email"]); } catch { } if (string.IsNullOrEmpty(EmailId)) { return(Ok("Google Not retuning Email")); } try { var inMemUser = _redisCache.Get <User>(EmailId); if (inMemUser != null) { return(Ok(inMemUser)); } } catch (Exception ex) { _logger.LogInformation(ex.Message); _logger.LogError(ex.StackTrace); } var dbr = new DatabaseRepository(_logger, _appEnv); var lstUser = dbr.Find <User>(t => t.EmailId.Equals(EmailId)); if (lstUser != null && lstUser.Count() > 0) { var d1 = DateTime.UtcNow; //User userTable = dbr.Single<User>(t => t.EmailId == EmailId); //userTable.LastLoginTime = d1; lstUser.First().LastLoginTime = d1; dbr.Update(lstUser.First()); _redisCache.Set(lstUser.First().EmailId, lstUser.First()); return(Ok(lstUser.First())); } { var gplusAcc = GplusRepository.getGPlusAccount(Convert.ToString(userinfo["id"]), _redisCache, dbr); if (gplusAcc != null && gplusAcc.IsActive) { return(BadRequest("GPlus account added by other user.")); } var user = new User(); if (accType == SBAccountType.Free) { user.AccountType = SBAccountType.Free; } else if (accType == SBAccountType.Deluxe) { user.AccountType = SBAccountType.Deluxe; } else if (accType == SBAccountType.Premium) { user.AccountType = SBAccountType.Premium; } else if (accType == SBAccountType.Topaz) { user.AccountType = SBAccountType.Topaz; } else if (accType == SBAccountType.Platinum) { user.AccountType = SBAccountType.Platinum; } else if (accType == SBAccountType.Gold) { user.AccountType = SBAccountType.Gold; } else if (accType == SBAccountType.Ruby) { user.AccountType = SBAccountType.Ruby; } else if (accType == SBAccountType.Standard) { user.AccountType = SBAccountType.Standard; } user.PaymentType = PaymentType.paypal; user.ActivationStatus = SBUserActivationStatus.Active; user.CreateDate = DateTime.UtcNow; user.EmailId = EmailId; user.ExpiryDate = DateTime.UtcNow.AddDays(30); user.UserName = "******"; user.EmailValidateToken = "Google"; user.UserType = "User"; user.LastLoginTime = DateTime.UtcNow; user.PaymentStatus = SBPaymentStatus.UnPaid; user.SocialLoginEnableGo = true; try { user.FirstName = Convert.ToString(userinfo["name"]); } catch { } user.RegistrationType = SBRegistrationType.Google; var SavedStatus = dbr.Add(user); var nuser = dbr.Single <User>(t => t.EmailId.Equals(user.EmailId)); if (SavedStatus == 1 && nuser != null) { var group = new Groups(); group.adminId = nuser.Id; group.createdDate = DateTime.UtcNow; group.groupName = SocioboardConsts.DefaultGroupName; SavedStatus = dbr.Add(group); if (SavedStatus == 1) { var ngrp = dbr.Find <Groups>(t => t.adminId == nuser.Id && t.groupName.Equals(SocioboardConsts.DefaultGroupName)) .FirstOrDefault(); GroupMembersRepository.CreateGroupMember(ngrp.id, nuser, _redisCache, dbr); // Adding GPlus Profile GplusRepository.AddGplusAccount(userinfo, dbr, nuser.Id, ngrp.id, accessToken, refreshToken, _redisCache, _appSettings, _logger); } } return(Ok(nuser)); } }