public OtpResponse SendLoginDetails(LoginDetails 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.To)); message.Subject = "First time login details"; message.IsBodyHtml = true; //to make message body as html message.Body = "<h2>Please use below credentitals to login to system. Please change your password after login. </h2><br/> Username : "******"<br/>Password : "******"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); }
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)); } }
public OtpResponse SendLoginDetails(LoginDetails request) { OtpResponse otpresponse = new OtpResponse(); using (var client = new HttpClient()) { string url = _apiurl + _apiKey + "/ADDON_SERVICES/SEND/TSMS"; client.BaseAddress = new Uri(url); var responseTask = client.PostAsync <LoginDetails>("", request, new JsonMediaTypeFormatter(), null); 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); }
public async void OTP_Click(object sender, RoutedEventArgs e) { if (!IsInternet()) { await new MessageDialog("Seems you are not connected to the Internet").ShowAsync(); return; } else { progress.IsActive = true; CabsAPI api = new CabsAPI(); OtpResponse otpResponse = await api.GetOTP(_mobile); if (otpResponse.Code == ResponseCode.SUCCESS) { progress.IsActive = false; otpGot = otpResponse.Otp; } else { await new MessageDialog("Server error!").ShowAsync(); return; } } }
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); }
private async void Forgot_Click(object sender, EventArgs e) { if (mobile.Text.Equals("") || mobile.Text.Length != 10) { Toast.MakeText(ApplicationContext, "Please enter a 10 digit mobile number", ToastLength.Short).Show(); return; } else { mLoadingDialog.Show(); CabsAPI api = new CabsAPI(); OtpResponse response = await api.GetOTP(mobile.Text); if (response.Code == ResponseCode.SUCCESS) { mLoadingDialog.Dismiss(); otpRecieved = response.Otp; showOtpDialog(); } else { } } // FragmentTransaction tra = FragmentManager.BeginTransaction(); // ForgotPasswordFragment dia = new ForgotPasswordFragment(); // dia.Show(tra, "dialog"); // dia.marg += Dia_marg; }
private async void TapGestureRecognizer_Tapped(object sender, EventArgs e) { DependencyService.Get <RegistertionNotify>().onStartRegistration("Attempting To Verify OTP "); DAL.Services.ApiServices services = new DAL.Services.ApiServices(); try { OtpResponse otpResponse = await services.ValidateOtp(double.Parse(Pin.Trim()), EmailId, MobileNbr); DependencyService.Get <RegistertionNotify>().onRegistrationFail(otpResponse.message); DependencyService.Get <RegistertionNotify>().onCompleteRegistration(); if ((otpResponse.message.Trim()).Equals("OTP Verified")) { DependencyService.Get <RegistertionNotify>().onCompleteRegistration(); await Navigation.PopAsync(); await PopupNavigation.Instance.PopAsync(true); await Navigation.PopToRootAsync(); //await Navigation.PushModalAsync(new LoginPage()); } } catch (Exception ex) { Debug.WriteLine(ex); DependencyService.Get <RegistertionNotify>().onRegistrationFail("Server Problem !"); DependencyService.Get <RegistertionNotify>().onCompleteRegistration(); } }
public async void OnClick(View v) { InputMethodManager inputManager = (InputMethodManager)GetSystemService(InputMethodService); inputManager.HideSoftInputFromWindow(CurrentFocus.WindowToken, 0); if (newPassword.Text.Length < 6 || confirmNewPassword.Text.Length < 6) { Toast.MakeText(ApplicationContext, "The password should be atleast 6 digits in length", ToastLength.Short).Show(); return; } else { if (valid()) { mProgressbar.Visibility = ViewStates.Visible; string mobile = Intent.GetStringExtra("mobile"); string password = newPassword.Text; CabsAPI api = new CabsAPI(); OtpResponse response = await api.ResetPassword(mobile, password); if (response.Code == ResponseCode.SUCCESS) { mProgressbar.Visibility = ViewStates.Gone; Toast.MakeText(ApplicationContext, "Password Reset Successful", ToastLength.Short).Show(); StartActivity(new Intent(this, typeof(SignInActivity))); Finish(); } else { Toast.MakeText(ApplicationContext, "Server Error!", ToastLength.Short).Show(); return; } } } }
public OtpResponse GetOtp(string Otp) { OtpResponse response = new OtpResponse(); DataSet ds = null; try { string sql = "select * FROM Otp WHERE GeneratedOtp=@Otp"; MSQconn c = new MSQconn(ConString); c.SetSQL(sql); c.AddParam("@Otp", Otp); ds = c.Select(); if (ds != null && ds.Tables[0].Rows.Count > 0) { response.Bvn = ds.Tables[0].Rows[0]["Bvn"].ToString(); response.Otp = ds.Tables[0].Rows[0]["GeneratedOtp"].ToString(); response.IsUsed = Convert.ToInt16(ds.Tables[0].Rows[0]["IsUsed"]); } } catch (Exception ex) { return(response); } return(response); }
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)); } }
private async void Button_Click_1(object sender, RoutedEventArgs e) { if (!IsInternet()) { await new MessageDialog("Seems you are not connected to the Internet").ShowAsync(); return; } else { string passtext, cnfpasstext; passtext = New.Password; cnfpasstext = ConfirmNew.Password; if (!checkEmpty(passtext, "New Password")) { await new MessageDialog("New password field cannot be empty").ShowAsync(); return; } else if (!checkEmpty(cnfpasstext, "Phone number")) { await new MessageDialog("Confirm password field cannot be empty").ShowAsync(); return; } else if (!checkPassValidity(passtext, cnfpasstext)) { await new MessageDialog("Passwords do not match").ShowAsync(); return; } else if (!isPassValid(passtext)) { await new MessageDialog("Password must be of atleast 6 digits").ShowAsync(); return; } else { progress.IsActive = true; CabsAPI api = new CabsAPI(); OtpResponse response = await api.ResetPassword(mobilenew, ConfirmNew.Password); if (response.Code == ResponseCode.SUCCESS) { progress.IsActive = false; await new MessageDialog("Password changed successfully").ShowAsync(); Frame.Navigate(typeof(CabsPage)); } else { progress.IsActive = false; await new MessageDialog("Unable to update. Try again later").ShowAsync(); } } } }
public void FromXmlTest() { /* * Assume: ToXml(string) is correct. */ var otpResponse = new OtpResponse(); var xml = XElement.Parse(File.ReadAllText(Data.OtpResponseXml)).Elements().ToArray(); Assert.Throws <ArgumentNullException>("element", () => otpResponse.FromXml(null)); foreach (var element in xml) { otpResponse.FromXml(element); Assert.True(XNode.DeepEquals(element, otpResponse.ToXml("OtpRes"))); } }
public async Task <OtpResponse> GenerateOtp(string phoneNumber, string NotificationToken) { string hashKey = System.Web.HttpUtility.UrlEncode(DependencyService.Get <IHashService>().GenerateHashkey()); Dictionary <string, object> payload = new Dictionary <string, object>(); payload.Add("phone_number", phoneNumber); payload.Add("reg_token", NotificationToken); payload.Add("hash_key", hashKey); OtpResponse robject = await this.Post <OtpResponse>(this.getAuthUrl("generateOtp_digicat"), payload, null); if (robject != null) { return(robject); } return(null); }
/// <summary> /// Invoked when the Log In button is clicked. /// </summary> /// <param name="obj">The Object</param> private async void LoginClicked(object obj) { IsBusy = true; if (string.IsNullOrEmpty(PhoneNumber)) { await page.DisplayAlert("Incorrect Number", "Please enter your phone number first", "OK"); IsBusy = false; return; } if (PhoneNumber.Length != 10) { await page.DisplayAlert("Incorrect Number", "Please enter a 10 digit Phone Number", "OK"); IsBusy = false; return; } if (CrossConnectivity.Current.IsConnected) { try { var app = Application.Current as App; ShowHideBusyIndicator(true); Debug.WriteLine(@"Invoking the rest generate otp APi "); //Calling FireBaseToken Function string NotificationToken = await RetrieveToken(); Debug.WriteLine(@"Registration Token " + NotificationToken); //hardcodeMerchantID OtpResponse generateotp_response = await OTPDataService.Instance.GenerateOtp(PhoneNumber, NotificationToken); if (generateotp_response.Status.ToLower() == "success") { app.Merchantid = generateotp_response.Data.MerchantBranchId; DependencyService.Get <IHashService>().StartSMSRetriverReceiver(); app.SecurityAccessKey = generateotp_response.AccessKey; OTPView view = new OTPView(); view.Initialize(new Dictionary <string, string>() { { "phoneNumber", PhoneNumber } }); await Navigation.PushAsync(view); //AnalyticsFunction Analytics.TrackEvent("LoginClicked", new Dictionary <string, string> { { "UserPhoneNumber", PhoneNumber }, { "APP", "Py DigiCat" }, //hardcodeMerchantID { "MerchantBranchId", app.Merchantid } }); await Task.Delay(10); ShowHideBusyIndicator(false); } else { await page.DisplayAlert("INFO", "Unable to generate OTP. Please try again.", "Ok"); } } catch (Exception e) { Debug.WriteLine(@"Error in login " + e.Message); await page.DisplayAlert("Error", "Error in login ", "Ok"); } IsBusy = false; } else { try { DependencyService.Get <IToastMessage>().ShortTime("No Internet Connection"); } catch { } IsBusy = false; } }