public int VerifyOTP(OTPVerification otpVerify)
        {
            //OTP
            int otpValue = new Random().Next(1000, 9999);
            //------------------------
            string recipient = otpVerify.MobileNumber;

            // string APIKey = "YhXzmkn/LGA-ECfHcE62lySEGYjUIsvD3Q1xgJogSu";
            string APIKey  = "	ta4CU4qPeg4-wtcxjqOwmc9kguaVbeCrrfxBegIrc7";
            string message = "Your OTP is " + otpValue;

            //string encodeMessage = HttpUtility.UrlEncode(message);

            //using (var webClient = new WebClient())
            //{
            //    byte[] response = webClient.UploadValues("https://api.textlocal.in/send", new NameValueCollection()
            //        {
            //            {"apikey",APIKey },
            //            {"numbers",recipient },
            //            { "message",encodeMessage},
            //            {"sender","TXTLCL" }
            //        });
            //   string results = System.Text.Encoding.UTF8.GetString(response);
            // var jsonObject = JObject.Parse(results);


            ///}
            return(otpValue);
        }
        public void InsertOTP()
        {
            IsOnline = VerifyInternet();
            if (IsOnline)
            {
                OTPVerification objOTP = new OTPVerification();
                objOTP.PhoneNumber = PhoneNumber;
                objOTP.OTP         = random_number;
                objOTP.StartTime   = DateTime.Now;
                objOTP.ExpiryTime  = DateTime.Now.AddMinutes(5);
                objOTP.Status      = Convert.ToInt32(1);
                objOTP.CreatedBy   = CustomerID;

                if (App.Current.Properties.ContainsKey("RefreshedToken"))
                {
                    objOTP.DeviceID = Convert.ToString(App.Current.Properties["RefreshedToken"]).Trim();
                }
                else
                {
                    objOTP.DeviceID = "";
                }

                if (App.Current.Properties.ContainsKey("apitoken"))
                {
                    var json    = JsonConvert.SerializeObject(objOTP);
                    var content = new StringContent(json, Encoding.UTF8, "application/json");
                    dal_Customer = new DALCustomer();
                    OTPVerification resultObj = dal_Customer.InsertOTP(Convert.ToString(App.Current.Properties["apitoken"]), objOTP);

                    if (resultObj.OTPVerificationID != 0)
                    {
                        OTPVerificationID = resultObj.OTPVerificationID;
                    }
                    else
                    {
                        DisplayAlert("", "Failed to generate OTP", "Ok");
                    }
                }
            }
            else
            {
                DisplayAlert("", "Please check your network connectivity", "Ok");
                return;
            }
        }
        public OTPVerification InsertOTP(string accessToken, OTPVerification objOTP)
        {
            OTPVerification obj_OTP = new OTPVerification();

            try
            {
                string baseUrl = Convert.ToString(App.Current.Properties["BaseURL"]);
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(baseUrl);
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    // Add the Authorization header with the AccessToken.
                    client.DefaultRequestHeaders.Add("Authorization", "bearer  " + accessToken);
                    // create the URL string.
                    string url = "api/InstaConsumer/InsertOTP";
                    // make the request

                    var json    = JsonConvert.SerializeObject(objOTP);
                    var content = new StringContent(json, Encoding.UTF8, "application/json");
                    HttpResponseMessage response = client.PostAsync(url, content).Result;
                    if (response.IsSuccessStatusCode)
                    {
                        string jsonString = response.Content.ReadAsStringAsync().Result;
                        if (jsonString != null)
                        {
                            APIResponse apiResult = JsonConvert.DeserializeObject <APIResponse>(jsonString);

                            if (apiResult.Result)
                            {
                                obj_OTP = JsonConvert.DeserializeObject <OTPVerification>(Convert.ToString(apiResult.Object));
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(obj_OTP);
        }
Beispiel #4
0
        public IHttpActionResult DeviceVerificationByUser([FromBody] OTPVerification OTP)
        {
            string Platform = HttpContext.Current.Request.Headers["platform"].ToString();
            string message  = string.Empty;
            var    result   = false;
            var    response = new ResponseSingleModel <string>();
            string token    = string.Empty;

            if (Platform.ToLower() == "web")
            {
                using (var userRepository = new UserRepository())
                {
                    result = userRepository.VerificationMobileEmail(OTP.userId, OTP.OTP, false, out token, out message).Response;
                }
            }
            else if (Platform.ToLower() == "mobile")
            {
                using (var userRepository = new UserRepository())
                {
                    result = userRepository.VerificationMobileEmail(OTP.userId, OTP.OTP, true, out token, out message).Response;
                }
            }
            if (!string.IsNullOrEmpty(message))
            {
                log.Info(message);
            }

            if (!string.IsNullOrEmpty(token))
            {
                UsersSession.userTokenDic.TryAdd(token, OTP.userId);
            }

            response.Response = token;
            response.Status   = result ? Constants.WebApiStatusOk : Constants.WebApiStatusFail;
            response.Message  = message;
            return(Ok(new { response.Status, data = response }));
        }
        public async Task <ActionResult <OTPVerification> > SendOTP(OTPVerification otpVerify)
        {
            var result = await Task.FromResult(VerifyOTP(otpVerify));

            return(Ok(result));
        }
        private async void btn_VerifyOTPClicked(object sender, EventArgs e)
        {
            IsOnline = VerifyInternet();
            if (IsOnline)
            {
                btnVerify.IsVisible = false;
                ShowLoading(true);

                if ((OTP1.Text != "" && OTP1.Text != null) && (OTP2.Text != "" && OTP2.Text != null) &&
                    (OTP3.Text != "" && OTP3.Text != null) && (OTP4.Text != "" && OTP4.Text != null))
                {
                    OTPVerification objOTP = new OTPVerification();
                    objOTP.OTPVerificationID = OTPVerificationID;
                    objOTP.PhoneNumber       = PhoneNumber;
                    objOTP.OTP        = OTP1.Text + OTP2.Text + OTP3.Text + OTP4.Text;
                    objOTP.ExpiryTime = DateTime.Now;
                    objOTP.CreatedBy  = CustomerID;

                    if (App.Current.Properties.ContainsKey("apitoken"))
                    {
                        var json    = JsonConvert.SerializeObject(objOTP);
                        var content = new StringContent(json, Encoding.UTF8, "application/json");
                        dal_Customer = new DALCustomer();
                        OTPVerification resultObj = dal_Customer.VerifyOTP(Convert.ToString(App.Current.Properties["apitoken"]), objOTP);

                        if (resultObj.OTPVerificationID != 0)
                        {
                            CustomerID = resultObj.CustomerID;
                            App.Current.Properties["CustomerID"]   = Convert.ToString(resultObj.CustomerID);
                            App.Current.Properties["UserName"]     = Convert.ToString(resultObj.Name);
                            App.Current.Properties["PhoneNumber"]  = Convert.ToString(PhoneNumber);
                            App.Current.Properties["Email"]        = Convert.ToString(resultObj.Email);
                            App.Current.Properties["ProfileImage"] = resultObj.ProfileImage;
                            ShowLoading(false);
                            //GetListOfCustomerVehicles();

                            if (NewORExisting == "EXISTING")
                            {
                                DisplayAlert("", "Welcome back " + Name + "! Thank you for using Instaparking", "Ok");
                            }
                            //await Navigation.PushAsync(new MasterPage(objLocationParkingLotFilter));
                            await Navigation.PushAsync(new Home(null, CustomerID));
                        }
                        else
                        {
                            btnVerify.IsVisible = true;
                            ShowLoading(false);
                            DisplayAlert("", "Please enter valid OTP", "Ok");
                        }
                    }
                    else
                    {
                        btnVerify.IsVisible = true;
                        ShowLoading(false);
                    }
                }
                else
                {
                    btnVerify.IsVisible = true;
                    ShowLoading(false);
                    DisplayAlert("", "Please enter OTP sent to " + PhoneNumber + "", "Ok");
                }
            }
            else
            {
                await DisplayAlert("", "Please check your network connectivity", "Ok");

                return;
            }
        }