Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConfigPath ¶
ConfigPath returns the path to a configuration file. The path is as:
os.UserConfigDir() + "appConfigGroup/appShortName/fileName"
Usually this function is used to get the path to config file in the same directory as the database file is stored.
Types ¶
type AuthStartRequest ¶
type AuthStartRequest struct {
Username string `json:"username"`
}
AuthStartRequest is a request for starting the authentication process.
type AuthVerifyRequest ¶
AuthVerifyRequest is a request for verifying the authentication code.
type DB ¶
DB represents the application's database.
type Teleauth ¶
type Teleauth struct {
// contains filtered or unexported fields
}
Teleauth holds telegram bot token and authentification codes
func New ¶
New creates a new Teleauth. Returns a new Teleauth or an error. Parameters:
- token: Telegram bot token
- appConfigGroup: Configuration group name
- appShortName: Application short name
The appConfigGroup and appShortName are used to get the path to the database file. The database file is "teleauth.db" and is created if it does not exist. The path to the database file make as:
os.UserConfigDir() + "appConfigGroup/appShortName/teleauth.db"
func (*Teleauth) HandleAuthStart ¶
func (t *Teleauth) HandleAuthStart(w http.ResponseWriter, r *http.Request)
HandleAuthStart is a HTTP handler for starting the authentication process.
It expects a JSON body with a single field "username". If the request method is not POST or the body is invalid, it returns an error response.
If the username is not found in the database, it returns a 404 status code with an error message.
If the database query fails, it returns a 500 status code with an error message.
If the code sending fails, it returns a 500 status code with an error message.
On success, it returns a 200 status code with a success message.
func (*Teleauth) HandleAuthVerify ¶
func (t *Teleauth) HandleAuthVerify(w http.ResponseWriter, r *http.Request)
HandleAuthVerify is a HTTP handler for verifying the authentication code.
It expects a JSON body with two fields: "username" and "code". If the request method is not POST or the body is invalid, it returns an error response.
If the username is not found in the database, it returns a 404 status code with an error message.
If the database query fails, it returns a 500 status code with an error message.
If the code is invalid or expired, it returns a 401 status code with an error message.
On success, it returns a 200 status code with a success message and a real API token/key.