Exemple #1
0
        public bool BlockUnBlockUser(string contactToken, bool isWeb, bool allowed)
        {
            try
            {
                UserManager mgr = new UserManager();
                TokenInfo tokenInfo = new HelperMethods().GetUserToken<TokenInfo>(isWeb, HttpContext.Current);
                if (!String.IsNullOrWhiteSpace(contactToken))
                {
                    if (allowed)
                        return mgr.UnBlockUser(tokenInfo.Idf, JsonWebToken.DecodeToken<TokenInfo>(contactToken, CodeHelper.SecretAccessKey, true, false).Idf);
                    return mgr.BlockUser(tokenInfo.Idf, JsonWebToken.DecodeToken<TokenInfo>(contactToken, CodeHelper.SecretAccessKey, true, false).Idf);
                }

                throw new Exception(CodeHelper.UnableToUpdateProfilePicture);
            }
            catch (Exception ex)
            {
                throw new WebFaultException<string>(ex.Message, System.Net.HttpStatusCode.InternalServerError);
            }
        }
Exemple #2
0
        public string AddUser(UserInfo info, ResourceInfo resourceInfo)
        {
            try
            {
                if (!String.IsNullOrWhiteSpace(resourceInfo.DataUrl))
                    resourceInfo.Data = JsonWebToken.Base64UrlDecode(resourceInfo.DataUrl);

                string reqHeader = HttpContext.Current.Request.Headers[CodeHelper.HeaderAccessKey];
                if (!String.IsNullOrEmpty(reqHeader))
                {
                    // If token is valid then add user
                    if (TokenAuthorization.CheckBasicAuthorization(reqHeader))
                    {
                        UserManager mgr = new UserManager();
                        // gets territory id by country code
                        TerritoryManager trMgr = new TerritoryManager();
                        info.TerritoryId = trMgr.GetTerritoryIdByCountryCode(info.CountryCode, trMgr.GetTerritoryList()).Id;
                        if (!String.IsNullOrWhiteSpace(info.UserName) && !String.IsNullOrWhiteSpace(info.DisplayName) && !String.IsNullOrWhiteSpace(info.OwnNumber)
                            && !String.IsNullOrWhiteSpace(info.Status) && !String.IsNullOrWhiteSpace(info.SerialNum) && !String.IsNullOrWhiteSpace(info.ComId))
                            return mgr.AddUser(info, resourceInfo);
                        throw new Exception(CodeHelper.UnableToAddUser);
                    }

                    // throw exception stating token is invalid
                    throw new Exception(CodeHelper.InvalidToken);
                }

                throw new Exception(CodeHelper.InvalidHeader);
            }
            catch (Exception ex)
            {
                //HttpContext.Current.Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError;
                //return ex.Message;
                throw new WebFaultException<string>(ex.Message, System.Net.HttpStatusCode.InternalServerError);
            }
        }
Exemple #3
0
 public string ChangeProfilePicture(string data, bool isWeb)
 {
     try
     {
         UserManager mgr = new UserManager();
         TokenInfo tokenInfo = new HelperMethods().GetUserToken<TokenInfo>(isWeb, HttpContext.Current);
         if (!String.IsNullOrWhiteSpace(data))
             return mgr.ChangeProfilePicture(tokenInfo.Idf, tokenInfo.FolderPath, JsonWebToken.Base64UrlDecode(data));
         throw new Exception(CodeHelper.UnableToUpdateProfilePicture);
     }
     catch (Exception ex)
     {
         throw new WebFaultException<string>(ex.Message, System.Net.HttpStatusCode.InternalServerError);
     }
 }
Exemple #4
0
 public ProfileInfo ViewProfileExternal(string contactToken, bool isWeb)
 {
     try
     {
         UserManager mgr = new UserManager();
         TokenInfo tokenInfo = new HelperMethods().GetUserToken<TokenInfo>(isWeb, HttpContext.Current);
         if (!String.IsNullOrWhiteSpace(contactToken))
         {
             TokenInfo contactTokenInfo = JsonWebToken.DecodeToken<TokenInfo>(contactToken, CodeHelper.SecretAccessKey, true, false);
             return mgr.ViewProfileExternal(tokenInfo.Idf, contactTokenInfo.Idf, Convert.ToInt32(contactTokenInfo.TerritoryId));
         }
         throw new Exception(CodeHelper.UnableToUpdateProfilePicture);
     }
     catch (Exception ex)
     {
         throw new WebFaultException<string>(ex.Message, System.Net.HttpStatusCode.InternalServerError);
     }
 }
Exemple #5
0
        public bool ValidateOTP(long id, string otp, bool isWeb)
        {
            try
            {
                string reqHeader = HttpContext.Current.Request.Headers[CodeHelper.HeaderAccessKey];
                if (!String.IsNullOrEmpty(reqHeader))
                {
                    // If token is valid then add user
                    if (TokenAuthorization.CheckBasicAuthorization(reqHeader))
                    {
                        UserManager mgr = new UserManager();
                        // gets territory id by country code
                        return mgr.ValidateOTP(id, otp);
                        throw new Exception(CodeHelper.UnableToAddUser);
                    }

                    // throw exception stating token is invalid
                    throw new Exception(CodeHelper.InvalidToken);
                }

                throw new Exception(CodeHelper.InvalidHeader);
            }
            catch (Exception ex)
            {
                //HttpContext.Current.Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError;
                //return ex.Message;
                throw new WebFaultException<string>(ex.Message, System.Net.HttpStatusCode.InternalServerError);
            }
        }
Exemple #6
0
 public List<SearchInfo> SearchUsers(string searchString,int pageId, int pageSize, bool isWeb)
 {
     try
     {
         UserManager mgr = new UserManager();
         HelperMethods helperMgr = new HelperMethods();
         TokenInfo tokenInfo = helperMgr.GetUserToken<TokenInfo>(isWeb, HttpContext.Current);
         return mgr.SearchUsers(tokenInfo.Idf, searchString, pageId, helperMgr.SetPageSize(pageSize, isWeb));
     }
     catch (Exception ex)
     {
         throw new WebFaultException<string>(ex.Message, System.Net.HttpStatusCode.InternalServerError);
     }
 }
Exemple #7
0
 public bool UpdateStatus(string status, bool isWeb)
 {
     try
     {
         UserManager mgr = new UserManager();
         Guid userIdf = new HelperMethods().GetUserIdf(isWeb, HttpContext.Current);
         return mgr.UpdateStatus(userIdf, status);
     }
     catch (Exception ex)
     {
         throw new WebFaultException<string>(ex.Message, System.Net.HttpStatusCode.InternalServerError);
     }
 }
Exemple #8
0
 public string RemoveProfilePicture(bool isWeb)
 {
     try
     {
         UserManager mgr = new UserManager();
         TokenInfo tokenInfo = new HelperMethods().GetUserToken<TokenInfo>(isWeb, HttpContext.Current);
         return mgr.RemoveProfilePicture(tokenInfo.Idf, tokenInfo.FolderPath);
         throw new Exception(CodeHelper.UnableToUpdateProfilePicture);
     }
     catch (Exception ex)
     {
         throw new WebFaultException<string>(ex.Message, System.Net.HttpStatusCode.InternalServerError);
     }
 }
Exemple #9
0
        public string LoginWeb(string token, string signalRIdf)
        {
            var tokenInfo = JsonWebToken.DecodeToken<TokenInfo>(token, CodeHelper.SecretAccessKey, true, false);

            UserManager mgr = new UserManager();

            var sampleTokenInfo = new TokenInfo() { Idf = tokenInfo.Idf, Expiry = DateTime.Now.AddMinutes(2), FolderPath = tokenInfo.FolderPath, TerritoryId = tokenInfo.TerritoryId };

            var sampleToken = JsonWebToken.Encode(sampleTokenInfo, CodeHelper.SecretAccessKey, HvHashAlgorithm.RS256);

            var obj = GlobalHost.ConnectionManager.GetHubContext<PushHub>();

            obj.Clients.Client(PushHub.loginUsers.Where(x => x.Key == signalRIdf).FirstOrDefault().Value).notifyUsers(sampleToken);

            return true.ToString();
        }
Exemple #10
0
 public bool FollowUnFollowUser(string contactToken, bool isWeb, bool follow)
 {
     try
     {
         UserManager mgr = new UserManager();
         TokenInfo tokenInfo = new HelperMethods().GetUserToken<TokenInfo>(isWeb, HttpContext.Current);
         if (!String.IsNullOrWhiteSpace(contactToken))
         {
             if (follow)
             {
                 TokenInfo contact = JsonWebToken.DecodeToken<TokenInfo>(contactToken, CodeHelper.SecretAccessKey, true, false);
                 NotificationInfo info = mgr.FollowUser(tokenInfo.Idf, contact.Idf, tokenInfo.TerritoryId);
                 var obj = GlobalHost.ConnectionManager.GetHubContext<HeyVoteHub>();
                 obj.Clients.Client(contact.Idf.ToString()).notifyUsers(new
                 {
                     Id = info.Id,
                     Title = info.Title,
                     UserIdf = info.UserIdf,
                     ImageIdf = info.ImageIdf,
                     FolderPath = info.FolderPath,
                     CreatedOn = info.CreatedOn,
                     DisplayName = info.DisplayName,
                 });
                 return true;
             }
             return mgr.UnFollowUser(tokenInfo.Idf, JsonWebToken.DecodeToken<TokenInfo>(contactToken, CodeHelper.SecretAccessKey, true, false).Idf);
         }
         throw new Exception(CodeHelper.UnableToUpdateProfilePicture);
     }
     catch (Exception ex)
     {
         throw new WebFaultException<string>(ex.Message, System.Net.HttpStatusCode.InternalServerError);
     }
 }
Exemple #11
0
        public string CheckIfUserExists(string number)
        {
            try
            {
                if (!String.IsNullOrWhiteSpace(number))
                {
                    string reqHeader = HttpContext.Current.Request.Headers[CodeHelper.HeaderAccessKey];
                    if (!String.IsNullOrEmpty(reqHeader))
                    {
                        //check basic token validation required for accessing webservice
                        if (TokenAuthorization.CheckBasicAuthorization(reqHeader))
                        {
                            UserManager mgr = new UserManager();
                            return mgr.CheckIfUserExists(number).ToString();
                        }

                        // throw exception stating token is invalid
                        throw new Exception(CodeHelper.InvalidToken);

                    }
                }
                // throw exception stating header is invalid
                throw new Exception(CodeHelper.InvalidHeader);
            }
            catch (Exception ex)
            {
                throw new WebFaultException<string>(ex.Message, System.Net.HttpStatusCode.InternalServerError);
            }
        }
Exemple #12
0
 public bool ChangeViewedNotificationStatus(string notificationIds, bool isWeb)
 {
     try
     {
         UserManager mgr = new UserManager();
         TokenInfo tokenInfo = new HelperMethods().GetUserToken<TokenInfo>(isWeb, HttpContext.Current);
         return mgr.ChangeViewedNotificationStatus(tokenInfo.Idf, notificationIds);
     }
     catch (Exception ex)
     {
         throw new WebFaultException<string>(ex.Message, System.Net.HttpStatusCode.InternalServerError);
     }
 }