コード例 #1
0
        public OTPResponse OtpActivation(OTPRequest request)
        {
            Logger.Debug("OTP Activation request received: {0}",
                         JsonConvert.SerializeObject(request, Formatting.Indented));


            OTPResponse response;

            //use in built data annotations to ensure model has binded correctly
            if (!ModelState.IsValid)
            {
                var errors = ModelState.Keys.SelectMany(key =>
                                                        ModelState[key].Errors.Select(x => x.ErrorMessage));
                response = new OTPResponse
                {
                    Success = false,
                    Message = "Form has validation errors",
                    Errors  = errors.ToArray()
                };
            }
            else
            {
                //send request to the user service and return the
                //response (success or fail)
                response = UserService.OtpActivation(request);
            }
            Logger.Debug("Sent OTP Response: {0}",
                         JsonConvert.SerializeObject(response, Formatting.Indented));
            return(response);
        }
コード例 #2
0
        public async Task <OTPResponse> SendOTP(SendOTPRequest oData)
        {
            OTPResponse sResponse = new OTPResponse();

            try
            {
                var users = await _userData.FindByUsernameAsync(oData.userName);

                if (users.Count > 0)
                {
                    var email        = users[0].email;
                    var mobile       = users[0].contactNo;
                    var userFullName = users[0].name;
                    var otp          = GenerateOTPNumber();
                    if (email == "")
                    {
                        sResponse.status  = "false";
                        sResponse.message = "Email does not exist for this user";
                    }
                    else
                    {
                        var otpSend = _userData.SendOTP(oData.userName, otp);
                        if (otpSend.msgRespone == true)
                        {
                            var sent = _mailService.ForgotPasswordOTPMail(otp, userFullName, email);
                            if (sent == true)
                            {
                                sResponse.status  = "true";
                                sResponse.message = otpSend.msg;
                            }
                            else
                            {
                                sResponse.status  = "false";
                                sResponse.message = "Mail sent Failed";
                            }
                        }
                        else
                        {
                            sResponse.status  = "false";
                            sResponse.message = otpSend.msg;
                        }
                    }
                }
                else
                {
                    sResponse.status  = "false";
                    sResponse.message = "Username does not exist";
                }
                return(sResponse);
            }
            catch (Exception e)
            {
                sResponse.status  = "false";
                sResponse.message = e.Message;
            }
            return(sResponse);
        }
コード例 #3
0
 public OTPVerificationPage(OTPResponse ObjOTPResponseModel)
 {
     InitializeComponent();
     _objOTPResponseModel             = ObjOTPResponseModel;
     _objOTPVerificationResponseModel = new OTPVerificationResponseModel();
     _apiServices = new RestApi();
     _baseUrl     = Settings.Url + Domain.OTPVerificationApiConstant;
     NavigationPage.SetHasNavigationBar(this, false);
     otpDescTxt.Text        = "we have sent you an OTP to" + " " + Settings.PhoneNo + " " + "Please enter the same here!";
     entryoOtpNo.Completed += (sender, e) =>
     {
         btnOtpSubmit_Clicked(sender, e);
     };
 }
コード例 #4
0
        private async Task <IEndpointResult> ProcessGenerateOTPRequestAsync(HttpContext context)
        {
            _logger.LogDebug("Start register request");

            var    form        = (await context.Request.ReadFormAsync()).AsNameValueCollection();
            var    phoneNumber = form.Get("phone_number");
            Random generator   = new Random();
            String otpCode     = generator.Next(0, 999999).ToString("D6");
            var    expiredDate = DateTime.Now.AddMinutes(5);
            var    response    = await _usersService.GenerateOTP(phoneNumber, otpCode, expiredDate);

            var otpResponse = new OTPResponse()
            {
                OTP         = otpCode,
                ExpiredDate = expiredDate
            };

            _logger.LogDebug("End register request");
            return(new GenerateOTPResult(otpResponse));
        }
コード例 #5
0
        public async Task <OTPResponse> ValidateOTP(OTPRequest oData)
        {
            OTPResponse sResponse = new OTPResponse();

            try
            {
                var users = await _usersData.FindByUsernameAsync(oData.userName);

                if (users.Count > 0)
                {
                    var otpvalidate = _usersData.ValidateOTP(oData);
                    if (otpvalidate.msgRespone == true)
                    {
                        sResponse.status  = "true";
                        sResponse.message = otpvalidate.msg;
                    }
                    else
                    {
                        sResponse.status  = "false";
                        sResponse.message = otpvalidate.msg;
                    }
                }
                else
                {
                    sResponse.status  = "false";
                    sResponse.message = "Username does not exist";
                }
                return(sResponse);
            }
            catch (Exception e)
            {
                sResponse.status  = "false";
                sResponse.message = e.Message;
            }
            return(sResponse);
        }
コード例 #6
0
        public async Task <OTPResponse> SendOTP(SendOTPRequest oData)
        {
            OTPResponse sResponse = new OTPResponse();

            try
            {
                var users = await _usersData.FindByUsernameAsync(oData.userName);

                if (users.Count > 0)
                {
                    var    email        = users[0].email;
                    var    mobile       = users[0].mobileNo;
                    var    userFullName = users[0].name;
                    var    otp          = GenerateOTPNumber();
                    var    host         = _config.GetSection("SMTPDetails").GetSection("host").Value;
                    var    port         = _config.GetSection("SMTPDetails").GetSection("port").Value;
                    var    uName        = _config.GetSection("SMTPDetails").GetSection("username").Value;
                    string pwd          = _config.GetSection("SMTPDetails").GetSection("pwd").Value;
                    string from         = _config.GetSection("SMTPDetails").GetSection("from").Value;
                    string cc           = _config.GetSection("ForgotPasswordSMTP").GetSection("recipients").Value;
                    string recipients   = email + cc;
                    string subject      = _config.GetSection("ForgotPasswordSMTP").GetSection("subject").Value;
                    string body         = _config.GetSection("ForgotPasswordSMTP").GetSection("message").Value + otp.ToString();

                    string mailTemplateSubject = _config.GetSection("ForgotPasswordMailTemplate").GetSection("Subject").Value;
                    string mailTemplateBody    = _config.GetSection("ForgotPasswordMailTemplate").GetSection("Body").Value;
                    string mailBody            = "";
                    //var forgetPasswordModel = JsonConvert.DeserializeObject<ForgetPassword>(mailTemplate);

                    if (email == "")
                    {
                        sResponse.status  = "false";
                        sResponse.message = "Email does not exist for this user";
                    }
                    else
                    {
                        mailBody = "";
                        mailBody = mailBody + mailTemplateBody.Replace("#OTP", otp).Replace("#RecipientName", userFullName);
                        var mailMessage = new MailMessage(from, recipients, mailTemplateSubject, mailBody);
                        mailMessage.IsBodyHtml = true;

                        var otpSend = _usersData.SendOTP(oData.userName, otp);
                        if (otpSend.msgRespone == true)
                        {
                            var client = new SmtpClient(host, int.Parse(port))
                            {
                                Credentials = new NetworkCredential(uName, pwd),
                                EnableSsl   = true
                            };
                            client.Send(mailMessage);
                            //client.Send(from, recipients, mailTemplateSubject, HttpUtility.HtmlDecode(mailBody));
                            sResponse.status  = "true";
                            sResponse.message = otpSend.msg;
                        }
                        else
                        {
                            sResponse.status  = "false";
                            sResponse.message = otpSend.msg;
                        }
                    }
                }
                else
                {
                    sResponse.status  = "false";
                    sResponse.message = "Username does not exist";
                }
                return(sResponse);
            }
            catch (Exception e)
            {
                sResponse.status  = "false";
                sResponse.message = e.Message;
            }
            return(sResponse);
        }
コード例 #7
0
 public GenerateOTPResult(OTPResponse users)
 {
     Users = users;
 }
コード例 #8
0
ファイル: RestApi.cs プロジェクト: rohitgit2k18/stetho
        public async Task <OTPVerificationResponseModel> OTPAsync(string uri, Boolean IsHeaderRequired, HeaderModel objHeaderModel, OTPResponse _objOTPResponseModel)
        {
            // client.MaxResponseContentBufferSize = 256000;
            OTPVerificationResponseModel _objOTPVerificationResponseModel = new OTPVerificationResponseModel();

            var keyValues = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("OTP", _objOTPResponseModel.OTP.ToString()),
                new KeyValuePair <string, string>("UserId", _objOTPResponseModel.UserId.ToString())
            };

            if (IsHeaderRequired)
            {
                client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
                client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Length", "69");
                client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "Fiddler");
                client.DefaultRequestHeaders.TryAddWithoutValidation("Host", "localhost:49165");
            }
            var request = new HttpRequestMessage(HttpMethod.Post, uri);

            request.Content = new FormUrlEncodedContent(keyValues);

            HttpResponseMessage response = await client.SendAsync(request);

            if (response.IsSuccessStatusCode)
            {
                var SucessResponse = await response.Content.ReadAsStringAsync();

                _objOTPVerificationResponseModel = JsonConvert.DeserializeObject <OTPVerificationResponseModel>(SucessResponse);
                return(_objOTPVerificationResponseModel);
            }
            else
            {
                var ErrorResponse = await response.Content.ReadAsStringAsync();

                //  ErrorResponse = ErrorResponse.Insert(1, "\"Status\"" + _col + "\"Fail\",");
                _objOTPVerificationResponseModel = JsonConvert.DeserializeObject <OTPVerificationResponseModel>(ErrorResponse);
                return(_objOTPVerificationResponseModel);
            }
        }