Exemple #1
0
        public HttpResponseMessage UserLogin([FromBody] tokenModel currentModel)
        {
            string token = "";

            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
            if (NeeoUtility.IsPhoneNumberInInternationalFormat(currentModel.uID))
            {
                NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidNumber);
            }
            if (!NeeoUtility.ValidatePhoneNumber(NeeoUtility.FormatAsIntlPhoneNumber(currentModel.uID)))
            {
                NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidNumber);
            }
            if (NeeoActivation.CheckUserAlreadyRegistered(currentModel.uID))
            {
                token = GenerateToken(currentModel.uID);
                return(Request.CreateResponse(HttpStatusCode.OK, token));
            }
            else
            {
                token = "-1";
                return(Request.CreateResponse(HttpStatusCode.Unauthorized, token));
            }
        }
Exemple #2
0
        /*They will be deprecated in future.*/

        /// <summary>
        /// Sends activation code to the phone number provided in <paramref name="phoneNumber"/>.
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="phoneNumber">A phone number on which activation code has to be sent.</param>
        /// <param name="devicePlatform">Platform of the user's device.</param>
        /// <param name="activationCode">A code that has to be sent on the give phone number.</param>
        /// <param name="isResend">A bool value indicating this is a resending code request if true,otherwise false (default value). </param>
        /// <param name="isRegenerated">A bool value indicating this is a regenerated code sending request if true,otherwise false (default value). </param>
        /// <returns>An integer if 0 = sms has not been sent, 1 = sms has been successfully sent or remaining minutes to unblock user.</returns>

        public int SendActivationCode(string phoneNumber, short devicePlatform, string activationCode, bool isResend, bool isRegenerated)
        {
            phoneNumber    = (phoneNumber != null) ? phoneNumber.Trim() : phoneNumber;
            activationCode = (activationCode != null) ? activationCode.Trim() : activationCode;
            int smsSendingResult = (int)SmsSendingStatus.SendingFailed;

            #region log user request and response

            /***********************************************
            *  To log user request and response
            ***********************************************/
            if (_logRequestResponse)
            {
                LogManager.CurrentInstance.InfoLogger.LogInfo(
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, System.Reflection.MethodBase.GetCurrentMethod().Name + " ===> " +
                    "Request ===> phoneNumber : " + phoneNumber + ", devicePlatform : " + devicePlatform +
                    ", activationCode : " + activationCode + ", isResend : " + isResend + ", isRegenerated : " +
                    isRegenerated);
            }

            #endregion

            //#region Verify User
            //var request = OperationContext.Current.IncomingMessageProperties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;
            //string keyFromClient = request.Headers["key"];
            //   if (NeeoUtility.AuthenticateUserRequest( phoneNumber, keyFromClient))
            //{
            //#endregion

            DevicePlatform userDevicePlatform = (DevicePlatform)devicePlatform;
            uint           tempActivationCode = 0;
            ulong          tempPhoneNumber    = 0;
            if (!NeeoUtility.IsNullOrEmpty(phoneNumber) && !NeeoUtility.IsNullOrEmpty(activationCode) && Enum.IsDefined(typeof(DevicePlatform), devicePlatform) && uint.TryParse(activationCode, out tempActivationCode) && ulong.TryParse(phoneNumber, out tempPhoneNumber))
            {
                try
                {
                    if (NeeoUtility.IsPhoneNumberInInternationalFormat(phoneNumber))
                    {
                        NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidNumber);
                        return(smsSendingResult);
                    }
                    if (!NeeoUtility.ValidatePhoneNumber(NeeoUtility.FormatAsIntlPhoneNumber(phoneNumber)) && _numberValidityCheck)
                    {
                        NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidNumber);
                        return(smsSendingResult);
                    }
                    smsSendingResult = NeeoActivation.SendActivationCodeToUnBlockedUser(phoneNumber, userDevicePlatform, activationCode, isResend, isRegenerated);
                }
                catch (ApplicationException appExp)
                {
                    NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)(Convert.ToInt32(appExp.Message)));
                }
                return(smsSendingResult);
            }
            NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidArguments);
            return(smsSendingResult);

            //}
            //   else
            //   {
            //       NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)HttpStatusCode.Unauthorized);
            //       return smsSendingResult;
            //   }
        }
Exemple #3
0
        ///// <summary>
        ///// Sends activation code to the phone number provided in <paramref name="ph"/>. It is a wrapping method with short parameter name.
        ///// </summary>
        ///// <remarks>
        ///// </remarks>
        ///// <param name="ph">A phone number on which activation code has to be sent.</param>
        ///// <param name="dP">Platform of the user's device.</param>
        ///// <param name="actCode">A code that has to be sent on the give phone number.</param>
        ///// <returns>An integer if 0 = sms has not been sent, 1 = sms has been successfully sent or remaining minutes to unblock user.</returns>
        //public int SendCodeTest(string ph, short dP, string actCode)
        //{
        //    #region log user request and response

        //    /***********************************************
        //     To log user request and response
        //     ***********************************************/
        //    if (_logRequestResponse)
        //    {
        //        LogManager.CurrentInstance.InfoLogger.LogInfo(
        //            System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, System.Reflection.MethodBase.GetCurrentMethod().Name + " ===> " +
        //            "Request ===> phoneNumber : " + ph + ", devicePlatform : " + dP +
        //            ", activationCode : " + actCode);
        //    }

        //    #endregion

        //    //return this.SendActivationCode(ph, dP, actCode, isRes, isReg);
        //    ph = (ph != null) ? ph.Trim() : ph;
        //    actCode = (actCode != null) ? actCode.Trim() : actCode;

        //    int smsSendingResult = (int)SmsSendingStatus.SendingFailed;
        //    DevicePlatform userDevicePlatform = (DevicePlatform)dP;
        //    uint tempActivationCode = 0;
        //    ulong tempPhoneNumber = 0;
        //    if (!NeeoUtility.IsNullOrEmpty(ph) && !NeeoUtility.IsNullOrEmpty(actCode) && Enum.IsDefined(typeof(DevicePlatform), dP))
        //    {
        //        try
        //        {
        //            if (NeeoUtility.IsPhoneNumberInInternationalFormat(ph))
        //            {
        //                NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidNumber);
        //                return smsSendingResult;
        //            }
        //            if (!NeeoUtility.ValidatePhoneNumber(NeeoUtility.FormatAsIntlPhoneNumber(ph)) && _numberValidityCheck)
        //            {
        //                NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidNumber);
        //                return smsSendingResult;
        //            }
        //            smsSendingResult = NeeoActivation.SendActivationCodeTest(ph, userDevicePlatform, actCode);
        //        }
        //        catch (ApplicationException appExp)
        //        {
        //            NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)(Convert.ToInt32(appExp.Message)));
        //        }

        //        return smsSendingResult;
        //    }
        //    NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidArguments);
        //    return smsSendingResult;
        //}

        /// <summary>
        /// Registers and configures user account. It is a wrapping method with short parameter name.
        /// </summary>
        /// <param name="ph">A string containing phone number for registering account.</param>
        /// <param name="client">An object containing the client information.</param>
        /// <returns>true if the account is successfully registered on the server; otherwise, false.</returns>
        public bool RegisterAppUser(string ph, UserAgent client)

        {
            ph = (ph != null) ? ph.Trim() : ph;
            #region log user request and response

            /***********************************************
            *  To log user request and response
            ***********************************************/
            if (_logRequestResponse)
            {
                LogManager.CurrentInstance.InfoLogger.LogInfo(
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, System.Reflection.MethodBase.GetCurrentMethod().Name + " ===> " +
                    "Request ===> phoneNumber : " + ph + ", client : " + JsonConvert.SerializeObject(client));
            }

            #endregion

            //        #region Verify User
            //var request = OperationContext.Current.IncomingMessageProperties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;
            //string keyFromClient = request.Headers["key"];
            //   if (NeeoUtility.AuthenticateUserRequest( ph, keyFromClient))
            //{
            //#endregion

            if (client != null)
            {
                ulong tempPhoneNumber = 0;

                if (!NeeoUtility.IsNullOrEmpty(ph) && !NeeoUtility.IsNullOrEmpty(client.DVenID) && !NeeoUtility.IsNullOrEmpty(client.AppID) && Enum.IsDefined(typeof(DevicePlatform), client.DP) && Enum.IsDefined(typeof(PushNotificationSource), client.Pns) && ulong.TryParse(ph, out tempPhoneNumber) && !NeeoUtility.IsNullOrEmpty(client.AppVer) && !NeeoUtility.IsNullOrEmpty(client.OsVer) && !NeeoUtility.IsNullOrEmpty(client.DM))
                {
                    try
                    {
                        if (NeeoUtility.IsPhoneNumberInInternationalFormat(ph))
                        {
                            NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidNumber);
                            return(false);
                        }
                        if (!NeeoUtility.ValidatePhoneNumber(NeeoUtility.FormatAsIntlPhoneNumber(ph)) && _numberValidityCheck)
                        {
                            NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidNumber);
                            return(false);
                        }
                        if (NeeoActivation.SetupUserAccount(ph, client.AppID, client.AppVer, new DeviceInfo()
                        {
                            DeviceModel = client.DM, DevicePlatform = (DevicePlatform)client.DP, DeviceVenderID = client.DVenID, DeviceToken = client.DToken?.Trim(), PushNotificationSource = (PushNotificationSource)client.Pns, OsVersion = client.OsVer, DeviceTokenVoIP = client.DTokenVoIP?.Trim()
                        }))
                        {
                            return(true);
                        }
                        NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.TransactionFailure);
                        return(false);
                    }
                    catch (ApplicationException appExp)
                    {
                        NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)(Convert.ToInt32(appExp.Message)));
                        return(false);
                    }
                }
            }
            NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidArguments);
            return(false);

            //}
            //   else
            //   {
            //       NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)HttpStatusCode.Unauthorized);

            //       return false;
            //   }
        }
Exemple #4
0
        /// <summary>
        /// Sends activation code to the phone number provided in <paramref name="ph"/>. It is a wrapping method with short parameter name.
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="ph">A phone number on which activation code has to be sent.</param>
        /// <param name="dP">Platform of the user's device.</param>
        /// <param name="actCode">A code that has to be sent on the give phone number.</param>
        /// <param name="isRes">A bool value indicating this is a resending code request if true,otherwise false (default value). </param>
        /// <param name="isReg">A bool value indicating this is a regenerated code sending request if true,otherwise false (default value). </param>
        /// <param name="appKey">A string containing the appKey(For Android).</param>
        /// <returns>An integer if 0 = sms has not been sent, 1 = sms has been successfully sent or remaining minutes to unblock user.</returns>
        public int SendActCode(string ph, short dP, string actCode, bool isRes, bool isReg, string appKey, short sType)
        {
            #region log user request and response

            /***********************************************
            *  To log user request and response
            ***********************************************/
            if (_logRequestResponse)
            {
                LogManager.CurrentInstance.InfoLogger.LogInfo(
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, System.Reflection.MethodBase.GetCurrentMethod().Name + " ===> " +
                    "Request ===> phoneNumber : " + ph + ", devicePlatform : " + dP +
                    ", activationCode : " + actCode + ", isResend : " + isRes + ", isRegenerated : " + isReg + ", appKey : " + appKey + ", serviceType: " + sType);
            }

            #endregion

            //return this.SendActivationCode(ph, dP, actCode, isRes, isReg);
            ph      = (ph != null) ? ph.Trim() : ph;
            actCode = (actCode != null) ? actCode.Trim() : actCode;
            appKey  = appKey?.Trim();

            int                codeSendingResult  = (int)SmsSendingStatus.SendingFailed;
            DevicePlatform     userDevicePlatform = (DevicePlatform)dP;
            CodeSendingService codeSendingService = (CodeSendingService)sType;
            uint               tempActivationCode = 0;
            ulong              tempPhoneNumber    = 0;
            if (!NeeoUtility.IsNullOrEmpty(ph) && !NeeoUtility.IsNullOrEmpty(actCode) && Enum.IsDefined(typeof(DevicePlatform), dP) && Enum.IsDefined(typeof(CodeSendingService), sType) && uint.TryParse(actCode, out tempActivationCode) && ulong.TryParse(ph, out tempPhoneNumber))
            {
                try
                {
                    if (NeeoUtility.IsPhoneNumberInInternationalFormat(ph))
                    {
                        NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidNumber);
                        return(codeSendingResult);
                    }
                    if (!NeeoUtility.ValidatePhoneNumber(NeeoUtility.FormatAsIntlPhoneNumber(ph)) && _numberValidityCheck)
                    {
                        NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidNumber);
                        return(codeSendingResult);
                    }

                    if (codeSendingService == CodeSendingService.Call)
                    {
                        codeSendingResult = NeeoActivation.CallForActivationCode(ph, userDevicePlatform, actCode);
                    }
                    else
                    {
                        codeSendingResult = NeeoActivation.SendActivationCode(ph, userDevicePlatform, actCode, appKey);
                    }
                }
                catch (ApplicationException appExp)
                {
                    NeeoUtility.SetServiceResponseHeaders((CustomHttpStatusCode)(Convert.ToInt32(appExp.Message)));
                }

                return(codeSendingResult);
            }

            NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidArguments);
            return(codeSendingResult);
        }