Exemplo n.º 1
0
        /// <summary>
        /// Get new session for the user on the basis of usermembership id
        /// </summary>
        /// <param name="userMembershipId"></param>
        /// <returns></returns>
        public Lead411UserInfo GetUserSessionUserMembershipWise(long userMembershipId)
        {
            try
            {
                Lead411UserInfo Lead411UserInfo = _iAccount.GetUserSessionUserMembershipWise(userMembershipId);

                return(Lead411UserInfo);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        public GmailService GetGmailServiceObject(string emailId)
        {
            GmailService    gmailService    = new GmailService();
            Lead411UserInfo Lead411UserInfo = _iAccount.GetUserSessionEmailWise(emailId);

            if (Lead411UserInfo != null)
            {
                var reqType = _iAccount.GetRequestType(emailId);

                if (Lead411UserInfo.Provider == AccountType.Gmail.ToString())
                {
                    var googleValidationResponse = new GoogleValidationResponse();
                    //Get new access token
                    if (Authentication.IsTokenExpired(Lead411UserInfo.AccessToken))
                    {
                        googleValidationResponse =
                            (GoogleValidationResponse)
                            Authentication.GetAccessTokenByRefreshToken(Lead411UserInfo.RefreshToken, reqType);
                        //Save new access token to db
                        _iAccount.SaveRefreshToken(Lead411UserInfo.RefreshToken, Lead411UserInfo.AccessToken,
                                                   Lead411UserInfo.Email, AccountType.Gmail);
                    }
                    else
                    {
                        googleValidationResponse.access_token = Lead411UserInfo.AccessToken;
                    }
                    if (googleValidationResponse.access_token != null)
                    {
                        Lead411UserInfo.AccessToken = googleValidationResponse.access_token;

                        //Get Userinfo
                        var tokeninfo = (Tokeninfo)Authentication.GetTokenInfo(Lead411UserInfo.AccessToken);

                        //Process emails

                        gmailService =
                            (GmailService)
                            Authentication.CreateAutherizationServiceObject(tokeninfo.Scope, tokeninfo.ExpiresIn,
                                                                            tokeninfo.UserId, Lead411UserInfo.AccessToken, Lead411UserInfo.RefreshToken);

                        //Process mails

                        var userCredential =
                            (UserCredential)
                            Authentication.CreateAutherizationObject(tokeninfo.Scope, tokeninfo.ExpiresIn,
                                                                     tokeninfo.UserId, Lead411UserInfo.AccessToken, Lead411UserInfo.RefreshToken);
                    }
                }
            }
            return(gmailService);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get user information by userid and access token. (After login when user start application next time it checks existance with this method.
        /// </summary>
        /// <param name="Lead411UserInfo"></param>
        /// <param name="reqType"></param>
        /// <returns></returns>
        public Lead411UserInfo GetUserInfoByUserId(
            Lead411UserInfo Lead411UserInfo,
            RequestType reqType)
        {
            if (Lead411UserInfo.Provider == AccountType.Gmail.ToString() && Authentication.IsTokenExpired(Lead411UserInfo.AccessToken))
            {
                var googleValidationResponse = (GoogleValidationResponse)Authentication.GetAccessTokenByRefreshToken(Lead411UserInfo.RefreshToken, reqType);
                if (!string.IsNullOrEmpty(googleValidationResponse.access_token))
                {
                    Lead411UserInfo.AccessToken = googleValidationResponse.access_token;
                    _iAccount.SaveRefreshToken(Lead411UserInfo.RefreshToken, Lead411UserInfo.AccessToken, Lead411UserInfo.Email, AccountType.Gmail);
                }
                else
                {
                    Lead411UserInfo = null;
                }
            }

            return(Lead411UserInfo);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Delete contact group created by dot align project.
        /// </summary>
        /// <param name="Lead411UserInfo"></param>
        /// <param name="reqType"></param>
        public async Task <bool> DeleteContactFolder(Lead411UserInfo Lead411UserInfo, RequestType reqType)
        {
            bool result = false;

            // Retrieving the contact group is required in order to get the Etag.
            try
            {
                GoogleValidationResponse googleValidationResponse = new GoogleValidationResponse();
                //Get new access token
                if (Authentication.IsTokenExpired(Lead411UserInfo.AccessToken))
                {
                    googleValidationResponse = (GoogleValidationResponse)Authentication.GetAccessTokenByRefreshToken(Lead411UserInfo.RefreshToken, reqType);
                    //Save new access token to db
                    _iAccount.SaveRefreshToken(Lead411UserInfo.RefreshToken, Lead411UserInfo.AccessToken, Lead411UserInfo.Email, AccountType.Gmail);
                }
                else
                {
                    googleValidationResponse.access_token = Lead411UserInfo.AccessToken;
                }
                if (googleValidationResponse.access_token != null)
                {
                    Lead411UserInfo.AccessToken = googleValidationResponse.access_token;
                    //Get Userinfo
                    Tokeninfo tokeninfo = (Tokeninfo)Authentication.GetUserProfile(Lead411UserInfo.AccessToken);

                    UserCredential userCredential = (UserCredential)Authentication.CreateAutherizationServiceObject(tokeninfo.Scope, tokeninfo.ExpiresIn, tokeninfo.UserId, Lead411UserInfo.AccessToken, Lead411UserInfo.RefreshToken);

                    ContactsRequest contactRequest = (ContactsRequest)Authentication.ContactsRequest(Lead411UserInfo.AccessToken, Lead411UserInfo.RefreshToken);

                    result = await Operation.DeleteContactFolder(contactRequest);
                }
            }
            catch //(GDataVersionConflictException e)
            {
                // Etags mismatch: handle the exception.
            }
            return(result);
        }
Exemplo n.º 5
0
        public async Task <IHttpActionResult> AccountSetting(
            long userMembershipId,
            SettingType settingType,
            bool deleteFolder,
            RequestType reqType)
        {
            ResponseModel responseModel = new ResponseModel();
            bool          success       = false;

            try
            {
                if (userMembershipId > 0) // && !string.IsNullOrEmpty(settingType))
                {
                    switch (settingType)
                    {
                    case SettingType.resetindexing:
                        success = _iCommonService.ResetIndexing(userMembershipId);
                        if (success)
                        {
                            responseModel.Message = CoreEntities.Helper.Messages.ResetSuccessfully;
                        }
                        break;

                    case SettingType.deleteaccount:
                        bool isSuccess = _iCommonService.DeleteAccount(userMembershipId);

                        if (isSuccess && deleteFolder)
                        {
                            Lead411UserInfo Lead411UserInfo =
                                _iCommonService.GetUserSessionUserMembershipWise(userMembershipId);

                            if (Lead411UserInfo.Provider == AccountType.Gmail.ToString())
                            {
                                success = await _googleServiceNew.DeleteContactFolder(Lead411UserInfo, reqType);
                            }
                        }

                        if (success)
                        {
                            responseModel.Message = CoreEntities.Helper.Messages.DeletedSuccessfully;
                        }

                        break;

                    default:
                        throw new ArgumentOutOfRangeException(nameof(settingType), settingType, null);
                    }

                    responseModel.Content   = success;
                    responseModel.IsSuccess = success;
                }
                else
                {
                    responseModel.Content   = "";
                    responseModel.Message   = CoreEntities.Helper.Messages.ProcessFailed;
                    responseModel.IsSuccess = false;
                }
            }
            catch (Exception ex)
            {
                responseModel.Content   = "";
                responseModel.Message   = ex.Message;
                responseModel.IsSuccess = false;
            }
            return(Ok(responseModel));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Process single mail on the call of web jobs.
        /// </summary>
        /// <param name="emailId"></param>
        public async Task ProcessSingleEmail(string emailId)
        {
            try
            {
                Lead411UserInfo Lead411UserInfo = _iAccount.GetUserSessionEmailWise(emailId);

                if (Lead411UserInfo != null)
                {
                    var reqType = _iAccount.GetRequestType(emailId);

                    if (Lead411UserInfo.Provider == AccountType.Gmail.ToString())
                    {
                        var googleValidationResponse = new GoogleValidationResponse();
                        //Get new access token
                        if (Authentication.IsTokenExpired(Lead411UserInfo.AccessToken))
                        {
                            googleValidationResponse =
                                (GoogleValidationResponse)
                                Authentication.GetAccessTokenByRefreshToken(Lead411UserInfo.RefreshToken, reqType);
                            //Save new access token to db
                            _iAccount.SaveRefreshToken(Lead411UserInfo.RefreshToken, Lead411UserInfo.AccessToken,
                                                       Lead411UserInfo.Email, AccountType.Gmail);
                        }
                        else
                        {
                            googleValidationResponse.access_token = Lead411UserInfo.AccessToken;
                        }
                        if (googleValidationResponse.access_token != null)
                        {
                            Lead411UserInfo.AccessToken = googleValidationResponse.access_token;

                            //Get Userinfo
                            var tokeninfo = (Tokeninfo)Authentication.GetTokenInfo(Lead411UserInfo.AccessToken);

                            //Process emails
                            var gmailService =
                                (GmailService)
                                Authentication.CreateAutherizationServiceObject(tokeninfo.Scope, tokeninfo.ExpiresIn,
                                                                                tokeninfo.UserId, Lead411UserInfo.AccessToken, Lead411UserInfo.RefreshToken);

                            //Get lable to process the mails
                            ////List<string> labels = await Operation.GetLabels(gmailService, tokeninfo.UserId);

                            //Process mails

                            var userCredential =
                                (UserCredential)
                                Authentication.CreateAutherizationObject(tokeninfo.Scope, tokeninfo.ExpiresIn,
                                                                         tokeninfo.UserId, Lead411UserInfo.AccessToken, Lead411UserInfo.RefreshToken);

                            var contactRequest =
                                (ContactsRequest)
                                Authentication.ContactsRequest(userCredential.Token.AccessToken,
                                                               userCredential.Token.RefreshToken);

                            var contactList = (List <Google.Contacts.Contact>) await Operation.GetContacts(contactRequest);

                            var           f    = contactRequest.GetContacts();
                            List <string> list = new List <string>();
                            foreach (Google.Contacts.Contact t in f.Entries)
                            {
                                foreach (var email in t.Emails)
                                {
                                    list.Add(email.Address.ToString());
                                }
                            }
                            //await MailProcess.Process(gmailService, tokeninfo.UserId, labels,
                            //    Lead411UserInfo.UserMembershipId, userCredential, contactList,
                            //    contactRequest);
                        }
                        else
                        {
                            //Disable account
                            _iAccount.DisableAccount(Lead411UserInfo.UserMembershipId);
                            //Send mail for relogin
                            EmailHelper.SendEmail(Lead411UserInfo.Email,
                                                  "Your account is inactive, Please login to Lead411 to activate it.",
                                                  "Lead411: Inactive Notification");
                        }
                    }
                }
                else
                {
                }
                //return true;
            }
            catch (Exception)
            {
                // return false;
            }
        }