Skip to content

Commit

Permalink
bug fixed, new method added
Browse files Browse the repository at this point in the history
  • Loading branch information
rohit-chouhan committed Oct 29, 2023
1 parent 1223ec6 commit 8b4d075
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 45 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,13 @@

* bug fixed
* new cool email template
* new feature added for custom SMTP
* new feature added for custom SMTP

## 2.0.1

* bug fixed

## 2.1.0

* bug fixed
* Customize Template [added]
127 changes: 87 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,82 @@
A fast & simple email authentication OTP sender and verification flutter package. It generates an OTP on the recipient's email which can be used to verify their identity.
# Welcome to Email OTP: Your Fast and Simple Email Authentication OTP Solution!

<p align="center"><img src="https://raw.githubusercontent.com/rohit-chouhan/email_otp/main/banner.jpg"/></p>
Email OTP is a Flutter package designed to simplify email authentication through one-time passwords (OTPs). With Email OTP, you can effortlessly generate OTPs and send them to your users' email addresses, ensuring secure identity verification.

![Email OTP Banner](https://raw.githubusercontent.com/rohit-chouhan/email_otp/main/banner.jpg)

[![rohit-chouhan](https://user-images.githubusercontent.com/82075108/182797964-a92e0c59-b9ef-432d-92af-63b6475a4b1c.svg)](https://www.github.com/rohit-chouhan)
_[![sponsor](https://user-images.githubusercontent.com/82075108/182797969-11208ddc-b84c-4618-8534-18388d24ac18.svg)](https://github.com/sponsors/rohit-chouhan)
[![sponsor](https://user-images.githubusercontent.com/82075108/182797969-11208ddc-b84c-4618-8534-18388d24ac18.svg)](https://github.com/sponsors/rohit-chouhan)

## Table of Contents
- [Getting Started](#getting-started)
- [Usage](#usage)
- [Configuration](#configuration)
- [Customizing Email Templates (Optional)](#customizing-email-templates-optional)
- [Configuring Custom SMTP (Optional)](#configuring-custom-smtp-optional)
- [Sending and Verifying OTPs](#sending-and-verifying-otps)
- [Complete Example](#complete-example)
- [Reporting Bugs or Issues](#reporting-bugs-or-issues)
- [Copyright and License](#copyright-and-license)

#### Usage
```
## Getting Started

To get started, import the `email_otp` package in your Flutter project:

```dart
import 'package:email_otp/email_otp.dart';
```
#### Methods
**Class Initialization**

## Usage

Initialize the EmailOTP class:

```dart
EmailOTP myauth = EmailOTP();
EmailOTP myAuth = EmailOTP();
```
**setConfig()**
this function will config your OTP authentication.

## Configuration

Configure your OTP authentication settings using the `setConfig` method:

```dart
myauth.setConfig(
myAuth.setConfig(
appEmail: "[email protected]",
appName: "Email OTP",
userEmail: email.text,
otpLength: 6,
otpType: OTPType.digitsOnly
);
```
1. `appEmail` is your personal or company email, so client we see this mail when they receive OTP.
2. `appName` is your app name, client will received mail with this name.
3. `userEmail` property where OTP need to sent.
4. `otpLength` is the length of OTP.
5. `otpType` OTPType.digitsOnly, OTPType.stringOnly, OTPType.mixed

**setSMTP()** (new)
1. `appEmail`: Your personal or company email address, visible to clients when they receive OTPs.
2. `appName`: Your app's name, displayed to clients in the email.
3. `userEmail`: The recipient's email address where the OTP needs to be sent.
4. `otpLength`: The length of the OTP (e.g., 6 digits).
5. `otpType`: Choose from `OTPType.digitsOnly`, `OTPType.stringOnly`, or `OTPType.mixed` for different OTP formats.

this function will config your SMTP to send OTP from custom email address, make sure your SMTP credentials are correct, test your SMTP from www.smtper.net
### Customizing Email Templates (Optional)

You can customize your email template using the `setTemplate` method. If not used, the default template provided by Email OTP will be used.

```dart
myauth.setSMTP(
var template = 'YOUR HTML CODE HERE';
myAuth.setTemplate(
render: template
);
```

In your HTML, use placeholders like `{{app_name}}` and `{{otp}}` to display the app name and OTP. For example:

```
Thank you for choosing {{app_name}}. Your OTP is {{otp}}.
```

### Configuring Custom SMTP (Optional)

Configure your SMTP settings using the `setSMTP` method if you want to send OTPs from a custom email address. Make sure your SMTP credentials are correct. Test your SMTP configuration at [smtper.net](https://www.smtper.net).

```dart
myAuth.setSMTP(
host: "smtp.rohitchouhan.com",
auth: true,
username: "[email protected]",
Expand All @@ -47,33 +85,42 @@ myauth.setSMTP(
port: 576
);
```
1. `host` is your SMTP Hostname
2. `auth` is your SMTP Email authetication required or not
3. `username` is your SMTP Email Address
4. `password` is your SMTP Email Password
5. `secure` TLS or SSL
6. `port` is port number of your SMTP Email Server

**sendOTP()**
this function will send OTP, and return boolean

1. `host`: Your SMTP hostname.
2. `auth`: Boolean (true/false) indicating if SMTP authentication is required.
3. `username`: Your SMTP email address.
4. `password`: Your SMTP email password.
5. `secure`: Choose from "TLS" or "SSL" for secure connections.
6. `port`: Port number of your SMTP email server.

## Sending and Verifying OTPs

Use the following methods to send and verify OTPs:

### Sending OTP

```dart
await myauth.sendOTP();
await myAuth.sendOTP();
```
**verifyOTP()**
this function will verify OTP, and return boolean. this method must have one parameter for OTP, which is enter by client.

### Verifying OTP

```dart
var inputOTP = 987654; //which is entered by client, after receive mail
await myauth.verifyOTP(
otp: inputOTP
var inputOTP = 987654; // OTP entered by the client after receiving the email
await myAuth.verifyOTP(
otp: inputOTP
);
```
#### See Complete Example
Code : [https://pub.dev/packages/email_otp/example](https://pub.dev/packages/email_otp/example "https://pub.dev/packages/email_otp/example")

# Report bugs or issues
## Complete Example

Find a complete example in the [Email OTP package documentation](https://pub.dev/packages/email_otp/example).

## Reporting Bugs or Issues

Feel free to open a [ticket](https://github.com/rohit-chouhan/email_otp/issues) on GitHub if you encounter any problems. We also welcome new ideas and suggestions.

You are welcome to open a _[ticket](https://github.com/rohit-chouhan/email_otp/issues)_ on github if any problems arise. New ideas are always welcome.
## Copyright and License

# Copyright and License
Copyright © 2023 [Rohit Chouhan](https://rohitchouhan.com). Licensed under the [MIT LICENSE](https://github.com/rohit-chouhan/otp/blob/main/LICENSE).

> Copyright © 2023 **[Rohit Chouhan](https://rohitchouhan.com)**. Licensed under the _[MIT LICENSE](https://github.com/rohit-chouhan/otp/blob/main/LICENSE)_.
Binary file modified banner.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 9 additions & 2 deletions lib/email_otp.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class EmailOTP {
//SMTP Port
int? _port;

//Custom HTML Template
String? _template;

//Function to set custom SMTP Configuration
setSMTP({host, auth, username, password, secure, port}){
_host = host;
Expand Down Expand Up @@ -71,6 +74,11 @@ class EmailOTP {
}
}

///Function use to use custom html template
setTemplate({render}) {
_template = render;
}

///Function will return true / false
sendOTP() async {
var url = Uri.parse('https://flutter.rohitchouhan.com/email-otpV2/v2.php');
Expand All @@ -80,6 +88,7 @@ class EmailOTP {
"user_email": _userEmail,
"otp_length": _otpLength,
"type": _type,
"template":_template,
"smtp_host":_host,
"smtp_auth":_auth,
"smtp_username":_username,
Expand Down Expand Up @@ -114,10 +123,8 @@ class EmailOTP {
///Function will return true / false
verifyOTP({otp}) {
if (_getOTP == otp) {
print("OTP has been verified! ✅");
return true;
} else {
print("OTP is invalid ❌");
return false;
}
}
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: email_otp
description: A fast & simple email authentication OTP sender and verification flutter package.
version: 2.0.1
version: 2.1.0
homepage: https://rohitchouhan.com
repository: https://github.com/rohit-chouhan/email_otp

Expand All @@ -11,7 +11,7 @@ environment:
dependencies:
flutter:
sdk: flutter
http: ^0.13.4
http: ^1.1.0

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 8b4d075

Please sign in to comment.