public HttpResponseMessage RegisterAdmin([FromBody] AdminRegisterModels AdminInfo)
        {
            try
            {
                if (AdminInfo != null)
                {
                    string otp = new LoginHelper().GenerateRandomOtp();

                    int result = bll.RegisterAdmin(AdminInfo.FirstName, AdminInfo.LastName, AdminInfo.Email, AdminInfo.Password, AdminInfo.PhoneNumber, AdminInfo.Address, AdminInfo.zipCode);

                    OtpRequest request = new OtpRequest()
                    {
                        Mobile = AdminInfo.PhoneNumber, Email = AdminInfo.Email, Otp = otp
                    };

                    // Uncomment below line if you want to send sms with otp
                    //OtpResponse response = notification.SendOTP(request);
                    OtpResponse emailresponse = emailNotification.SendOTP(request);

                    bll.SaveOtpInDatabase(AdminInfo.PhoneNumber, AdminInfo.Email, otp);

                    return(Request.CreateResponse(HttpStatusCode.OK, emailresponse));
                }

                return(Request.CreateResponse(HttpStatusCode.BadRequest, ""));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }
        }
Exemple #2
0
        public ActionResult ConfirmRegister(string otp)
        {
            var userDetails = (UserInfo)Session["RegisteredUserDetails"];

            if (userDetails != null)
            {
                OtpRequest otpRequest = new OtpRequest()
                {
                    Email     = userDetails.Email,
                    Mobile    = userDetails.Mobile,
                    Otp       = otp,
                    SessionId = string.Empty // this is required only to verify otp sent over sms, if we have used otp service
                };

                var response = registerApiController.ActivateRegisteredUser(otpRequest);

                if (response != null && response.IsSuccessStatusCode)
                {
                    ViewBag.Message = "We have sent you login details on your email and mobile.";
                }
                else
                {
                    ViewBag.SendOtpAgain = true;
                }
            }

            ModelState.AddModelError("otp", "Error in otp confirmation");
            return(View());
        }
Exemple #3
0
        public OtpResponse VerifyOTP(OtpRequest request)
        {
            OtpResponse otpresponse = new OtpResponse();

            using (var client = new HttpClient())
            {
                string url = _apiurl + _apiKey + "/SMS/VERIFY/" + request.SessionId + "/" + request.Otp;

                client.BaseAddress = new Uri(url);

                var responseTask = client.GetAsync("");
                responseTask.Wait();

                var result = responseTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    var readTask = result.Content.ReadAsAsync <OtpResponse>();
                    readTask.Wait();

                    otpresponse = readTask.Result;
                }
            }

            return(otpresponse);
        }
        public OtpResponse SendOTP(OtpRequest request)
        {
            OtpResponse response = new OtpResponse();

            try
            {
                string fromEmail         = GlobalConstants.FromEmail;
                string fromEmailPassword = GlobalConstants.FromEmailPasword;

                MailMessage message = new MailMessage();
                SmtpClient  smtp    = new SmtpClient();
                message.From = new MailAddress(fromEmail);
                message.To.Add(new MailAddress(request.Email));
                message.Subject            = "Test : OTP for registration";
                message.IsBodyHtml         = true; //to make message body as html
                message.Body               = "<h2>Please use below otp to confirm your registration.</h2> <br/> Your Otp Is: " + request.Otp;
                smtp.Port                  = 587;
                smtp.Host                  = "smtp.gmail.com"; //for gmail host
                smtp.EnableSsl             = true;
                smtp.UseDefaultCredentials = false;
                smtp.Credentials           = new NetworkCredential(fromEmail, fromEmailPassword);
                smtp.DeliveryMethod        = SmtpDeliveryMethod.Network;
                smtp.Send(message);

                response.Status  = "Success";
                response.Details = "Email sent successfully";
            }
            catch (Exception)
            {
                response.Status  = "Failed";
                response.Details = "Email sent failed";
            }
            return(response);
        }
Exemple #5
0
        protected void btnVerifyBVN_Click(object sender, EventArgs e)
        {
            formone.Visible = false;
            formtwo.Visible = true;
            if (cardBVN.Text == "" || txtCardNumber.Text == "" || txtCVV.Text == "" || txtPin.Text == "")
            {
                Response.Write("<script language='javascript'>alert('Please Fill All Fields');</script>");
                return;
            }

            try
            {
                NibssRepository nibss          = new NibssRepository();
                string          EndpointUrl    = $"{BaseUrl}/api/nibss/searchbvn?bvn={cardBVN.Text}";
                string          responseString = "";
                // var bvnSearchResponse = await new ApiRequest(EndpointUrl).MakeHttpClientRequest(null, ApiRequest.Verbs.GET, null);
                //if (bvnSearchResponse.StatusCode == System.Net.HttpStatusCode.OK)
                if (true)
                {
                    //  DefaultApiReponse<BvnSearchResp> response = Newtonsoft.Json.JsonConvert.DeserializeObject<DefaultApiReponse<BvnSearchResp>>(responseString);
                    var response = nibss.BvnSearch(cardBVN.Text);
                    //Session["BvnSearchResp"] = response.Object;
                    Session["BvnSearchResp"] = response;
                    Random rnd = new Random();
                    string Otp = rnd.Next(0, 9999).ToString("D4");
                    //string phoneNo = response.Object.PhoneNumber1;
                    string     phoneNo    = response.PhoneNumber2;
                    OtpRequest otpRequest = new OtpRequest
                    {
                        Bvn = cardBVN.Text,
                        Otp = Otp
                    };
                    EndpointUrl = $"{BaseUrl}/api/otp";

                    // var r = await new ApiRequest(EndpointUrl).MakeHttpClientRequest(otpRequest, ApiRequest.Verbs.POST, null);

                    //if (r.StatusCode == System.Net.HttpStatusCode.OK)
                    if (true)
                    {
                        //  responseString = await r.Content.ReadAsStringAsync();

                        //EmailSender.SendMail(response.Email, Otp);
                        mailTrxn.SendMailAlerts(response.Email, "Your otp is" + Otp, "Team Daze OTP");
                    }
                }
                else
                {
                    Alertdiv.InnerText = "Unable To Get BVN From NiBSS";
                    Alertdiv.Visible   = true;
                    return;
                }
            }
            catch (Exception ex)
            {
                //  new ErrorLog();
                TeamDaze.BLL.DAL.ErrorLog loggger = new ErrorLog(ex.ToString());
                Response.Write("<script language='javascript'>alert('an error occured, kindly try again');</script>");
                return;
            }
        }
        public HttpResponseMessage ActivateRegisteredUser([FromBody] OtpRequest request)
        {
            try
            {
                if (request != null)
                {
                    // Uncomment below line if you want to verify otp sent over sms
                    //OtpResponse smsResponse = notification.VerifyOTP(request);
                    OtpResponse emailResponse = emailNotification.VerifyOTP(request);

                    if (emailResponse.Status == "Success")
                    {
                        string password = new LoginHelper().GeneratePassword(8);

                        int result = bll.ActivateRegisteredUser(request.Mobile, password, request.Email, request.Otp);

                        // Uncomment below lines if you want to send first time login details over sms

                        //LoginDetails req = new LoginDetails()
                        //{
                        //    From = "VHAASH",
                        //    To = request.Mobile,
                        //    TemplateName = "ScoopenLoginAccount",
                        //    VAR1 = "User",
                        //    VAR2 = request.Mobile,
                        //    VAR3 = password
                        //};

                        //OtpResponse smsResponseLoginDetails = notification.SendLoginDetails(req);

                        LoginDetails emailreq = new LoginDetails()
                        {
                            From         = "VHAASH",
                            To           = request.Email,
                            TemplateName = "ScoopenLoginAccount",
                            VAR1         = "User",
                            VAR2         = request.Mobile,
                            VAR3         = password
                        };

                        OtpResponse emailResponseLoginDetails = emailNotification.SendLoginDetails(emailreq);

                        return(Request.CreateResponse(HttpStatusCode.OK, emailResponseLoginDetails));
                    }

                    return(Request.CreateErrorResponse(HttpStatusCode.NonAuthoritativeInformation, "OTP Not Matched"));
                }

                return(Request.CreateResponse(HttpStatusCode.BadRequest, ""));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }
        }
        public HttpResponseMessage ActivateRegisteredUser(OtpRequest request)
        {
            var registerHttpClient = new RegisterHttpClient();

            var response = registerHttpClient.ActivateRegisteredUser(request);

            if (response.IsSuccessStatusCode)
            {
                return(response);
            }
            return(null);
        }
Exemple #8
0
        public async Task <IApiResponse <int> > Insert(OtpRequest request)
        {
            int result = otpRepository.Insert(request.Bvn, request.Otp);

            return(await HandleApiOperationAsync(async() =>
            {
                return new DefaultApiReponse <int>
                {
                    Object = result
                };
            }));
        }
Exemple #9
0
        public void SendOtp(OtpRequest requestOTP, string OTPCode)
        {
            const string accountSid = "AC87601efb2dfbe5b990a8cf5945c21d84";
            const string authToken  = "cdb4b07e0ac2ddba61c0715de6250cac";

            TwilioClient.Init(accountSid, authToken);
            MessageResource.Create(
                body: $"Your verification code is : {OTPCode}",
                from: new Twilio.Types.PhoneNumber("+12025195159"),
                to: new Twilio.Types.PhoneNumber($"+84868684961")
                );
        }
Exemple #10
0
        public void SendOtp(OtpRequest requestOTP, string OTPCode)
        {
            string accountSid = "AC04da7ce1e879190ca577ca8d198cfafc";
            string authToken  = "af95a7f404a6591238080deaba00f9a2";

            TwilioClient.Init(accountSid, authToken);

            MessageResource.Create(
                body: $"Your verification code is : {OTPCode}",
                from: new Twilio.Types.PhoneNumber("+13342139746"),
                to: new Twilio.Types.PhoneNumber("+84868684961")
                );
        }
Exemple #11
0
        public async Task <IApiResponse <int> > Update(OtpRequest request)
        {
            int result = otpRepository.Update(request.Otp);

            string message = result != 1 ? "Invalid OTP" : "SUCCESS";

            return(await HandleApiOperationAsync(async() =>
            {
                return new DefaultApiReponse <int>
                {
                    Object = result,
                    ShortDescription = message
                };
            }));
        }
Exemple #12
0
        private async void ReturnInvalidOtpResponse()
        {
            var faker           = TestBuilder.Faker();
            var sessionId       = faker.Random.Hash();
            var testOtpResponse = new Response(ResponseType.OtpInvalid, "Invalid Otp");
            var testOtpRequest  = new OtpRequest
            {
                SessionId = sessionId, RequestedAt = It.IsAny <DateTime>(), OtpToken = faker.Random.String()
            };

            otpRepository.Setup(e => e.GetWith(sessionId)).ReturnsAsync(Option.Some(testOtpRequest));

            var otpResponse = await otpService.VerifyFor(sessionId, faker.Random.Hash());

            otpResponse.Should().BeEquivalentTo(testOtpResponse);
        }
Exemple #13
0
        private async void ReturnExpiredOtpResponse()
        {
            var sessionId       = TestBuilder.Faker().Random.Hash();
            var otpToken        = TestBuilder.Faker().Random.Number().ToString();
            var testOtpResponse = new Response(ResponseType.OtpExpired, "Otp expired");
            var testOtpRequest  = new OtpRequest
            {
                SessionId = sessionId, RequestedAt = DateTime.Now.ToUniversalTime().AddSeconds(-60), OtpToken = otpToken
            };

            otpRepository.Setup(e => e.GetWith(sessionId)).ReturnsAsync(Option.Some(testOtpRequest));

            var otpResponse = await otpService.VerifyFor(sessionId, otpToken);

            otpResponse.Should().BeEquivalentTo(testOtpResponse);
        }
        public HttpResponseMessage ActivateRegisteredUser(OtpRequest request)
        {
            using (ServiceClient)
            {
                var resource = string.Format("api/register");

                var response = ServiceClient.PutAsJsonAsync(resource, request).Result;

                if (response.IsSuccessStatusCode)
                {
                    return(response);
                }

                return(new HttpResponseMessage(HttpStatusCode.BadRequest));
            }
        }
        public void FromXmlTest()
        {
            /*
             * Assume:     ToXml(string) is correct.
             */
            var otpRequest = new OtpRequest();
            var xml        = XElement.Parse(File.ReadAllText(Data.OtpRequestXml)).Elements().ToArray();

            Assert.Throws <ArgumentNullException>("element", () => otpRequest.FromXml(null));

            foreach (var element in xml)
            {
                otpRequest.FromXml(element);
                Assert.True(XNode.DeepEquals(element, otpRequest.ToXml("Otp")));
            }
        }
        public OtpResponse VerifyOTP(OtpRequest request)
        {
            AccountControllerBLL bll = new AccountControllerBLL(new AccountControllerDAL());

            string otp = bll.GetOtpFromDatabase(request.Mobile, request.Email);

            if (otp == request.Otp)
            {
                return(new OtpResponse()
                {
                    Status = "Success", Details = "OTP Verified"
                });
            }
            return(new OtpResponse()
            {
                Status = "Failed", Details = "Incorrect"
            });
        }
Exemple #17
0
        public OtpResponse SendOtpToUser(OtpRequest requestOTP)
        {
            var resendTime = 60;
            var otpCode    = createOtpCode();
            var user       = GetByPhoneNumber(requestOTP.phonenumber);

            if (user == null)
            {
                var newUser = CreateAccount(new WorkerAccount()
                {
                    Phonenumber = requestOTP.phonenumber
                });
                user = newUser.Result;
            }
            SendOtp(requestOTP, otpCode);
            var token = generateJwtTokenRequestOTP(user, otpCode);

            return(new OtpResponse(resendTime, requestOTP, token));
        }
Exemple #18
0
        protected async void btnVerifyBVN_Click(object sender, EventArgs e)
        {
            Random rnd            = new Random();
            string EndpointUrl    = $"{BaseUrl}/api/nibss/searchbvn?bvn={txtBVN.Text}";
            string responseString = "";
            // NibssRepository nibssRepository = new NibssRepository();
            //var resp= nibssRepository.BvnSearch(txtBVN.Text);

            var bvnSearchResponse = await new ApiRequest(EndpointUrl).MakeHttpClientRequest(null, ApiRequest.Verbs.GET, null);

            if (bvnSearchResponse.StatusCode == System.Net.HttpStatusCode.OK)
            {
                responseString = await bvnSearchResponse.Content.ReadAsStringAsync();

                DefaultApiReponse <BvnSearchResp> response = Newtonsoft.Json.JsonConvert.DeserializeObject <DefaultApiReponse <BvnSearchResp> >(responseString);
                Session["BvnSearchResp"] = response.Object;
                string Otp     = rnd.Next(0, 9999).ToString("D4");
                string phoneNo = response.Object.PhoneNumber1;

                //Save Otp
                EndpointUrl = $"{BaseUrl}/api/otp";

                OtpRequest otpRequest = new OtpRequest
                {
                    Bvn = txtBVN.Text,
                    Otp = Otp
                };

                var headers = new Dictionary <string, string>();
                var r       = await new ApiRequest(EndpointUrl).MakeHttpClientRequest(otpRequest, ApiRequest.Verbs.POST, headers);

                if (r.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    responseString = await r.Content.ReadAsStringAsync();

                    string mailbody = "Dear Customer,<br/><br/> Your One Time OTP is " + Otp;

                    mailer.SendMailAlerts(response.Object.Email, mailbody, "Team Daze - One Time Password");
                }
                formoneaccount.Visible = false;
                formtwoaccount.Visible = true;
            }
        }
        public async Task <Response> Save(string otp, string sessionId)
        {
            try
            {
                var otpRequest = new OtpRequest
                {
                    SessionId = sessionId, RequestedAt = DateTime.Now.ToUniversalTime(), OtpToken = otp
                };
                otpContext.OtpRequests.Add(otpRequest);
                await otpContext.SaveChangesAsync();

                return(new Response(ResponseType.Success, "Otp Created"));
            }
            catch (Exception exception)
            {
                Log.Error(exception, exception.StackTrace);
                return(new Response(ResponseType.InternalServerError, "OtpGeneration Saving failed"));
            }
        }
Exemple #20
0
        public async Task <ServiceResponseModel <CCResponse> > ChargeWithOtp(OtpRequest req)
        {
            try
            {
                //var response = await _http.PostAsync<CCResponse>(baseUrl: StaticAppSettings.MeterAfBaseUrl, postdata: req, url: $"/api/charge/charge/{req.Otp}");

                PayServices ps       = new PayServices(_configuration, _http, _responseService);
                var         response = ps.SendOtp(req.refe, req.Otp).Result;
                if (response.status)
                {
                    return(_responseService.SuccessResponse <CCResponse>("Success! card Charged", response));
                }
                else
                {
                    return(_responseService.ErroResponse <CCResponse>("Unabe to charge card"));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #21
0
        public IActionResult RequestOtp(OtpRequest otpRequest)
        {
            var otpResponse = userService.SendOtpToUser(otpRequest);

            return(Ok(otpResponse));
        }
        public async Task <ActionResult <CCResponse> > ProcessCharge(OtpRequest req)
        {
            var response = await _pay.SendOtp(req.refe, req.Otp);

            return(response);
        }
Exemple #23
0
        protected async void btnValidateOtp_Click(object sender, EventArgs e)
        {
            string EndpointUrl    = $"{BaseUrl}/api/otp/?otp={txtOtp.Text}";
            var    GetOtpResponse = await new ApiRequest(EndpointUrl).MakeHttpClientRequest(null, ApiRequest.Verbs.GET, null);

            if (GetOtpResponse.StatusCode == System.Net.HttpStatusCode.OK)
            {
                string responseString = await GetOtpResponse.Content.ReadAsStringAsync();

                DefaultApiReponse <OtpResponse> response = Newtonsoft.Json.JsonConvert.DeserializeObject <DefaultApiReponse <OtpResponse> >(responseString);

                if (response == null)
                {
                    Response.Write("<script language='javascript'>alert('Invalid Otp');</script>");
                    return;
                }

                else if (response.Object.IsUsed == 1)
                {
                    Response.Write("<script language='javascript'>alert('Otp has been used already');</script>");
                    return;
                }
                else
                {
                    EndpointUrl = $"{BaseUrl}/api/otp/Validate";
                    OtpRequest otpRequest = new OtpRequest
                    {
                        Bvn = txtBVN.Text,
                        Otp = txtOtp.Text
                    };
                    var ValidateOtpResponse = await new ApiRequest(EndpointUrl).MakeHttpClientRequest(otpRequest, ApiRequest.Verbs.POST, null);

                    if (ValidateOtpResponse.StatusCode == System.Net.HttpStatusCode.OK)
                    {
                        string ValidateOTPResponseString = await ValidateOtpResponse.Content.ReadAsStringAsync();

                        DefaultApiReponse <int> ValidationResponse = Newtonsoft.Json.JsonConvert.DeserializeObject <DefaultApiReponse <int> >(ValidateOTPResponseString);
                        if (ValidationResponse.Object == 1)
                        {
                            //trigger thumbprint reader
                            //Save to DB
                            CustomerRepository customerRepository = new CustomerRepository();
                            BvnSearchResp      custObj            = (BvnSearchResp)Session["BvnSearchResp"];
                            Tuple <bool, List <CustomerCreation> > enrollmentResult = customerRepository.CreateCustomer(new CustomerCreation
                            {
                                BVN            = custObj.BVN,
                                EmailAddress   = custObj.Email,
                                FirstName      = custObj.FirstName,
                                LastName       = custObj.LastName,
                                PhoneNumber    = custObj.PhoneNumber1,
                                CardToken      = "",
                                CardType       = "",
                                EnrollmentType = "Account",
                                PanicFinger    = "",
                                MaxAmount      = 100000000000,
                            });

                            if (enrollmentResult.Item1)
                            {
                                Response.Redirect("Confirmation.aspx");
                            }
                            else
                            {
                                Response.Write("<script language='javascript'>alert('Profile cannot be created');</script>");
                                return;
                            }
                        }
                    }
                }
            }
        }