Sessionmanager
A little MySQL database to manage users.

Getting Started
Prerequisites
You need Docker or MySQL installed and check that mytap is a submodule and it is in the project folder.
Also you need Go installed with the following dependencies:
Installing
If you are using Docker go to the project folder and execute:
~/path_to_the_project$ ./initDocker.sh
In this file you can find the configuration of the MySQL server, feel free to modify it.
Then execute:
~/path_to_the_project$ ./initsql.sh
This file just sets up the database by default in the Docker machine. If you changed the configuration previously you must change it in this file or specify in the second parameter:
~/path_to_the_project$ ./initsql.sh '' mysql.ip
Installing dependencies:
~/path_to_the_project$ ./installDependencies.sh
Once the database is set up and the dependecies installed, build and run the server.go file.
~/path_to_the_project$ go build server.go
~/path_to_the_project$ ./server
Running the tests
To run the tests just execute de initsql script with the -t flag:
~/path_to_the_project$ ./initsql.sh -t
Like the previous step this tries to execute the tests in the Docker machine. You can change the ip by parameter:
~/path_to_the_project$ ./initsql.sh -t mysql.ip
To test the server integrated with the database run the tests with -databaseflag:
~/path_to_the_project$ go test ./... -v -database
API Usage
Register User
Registers a json given user.
-
URL
/Register
-
Method:
POST
-
URL Params
None
-
Data Params
{
"username":"Bob Smith",
"email":"mail@mail.com",
"password":"secretPassword"
}
-
Success Response:
-
Code: 201 CREATED
Content:
{
"Response": {
"Status": 201,
"Error": 1,
"Description": ""
}
}
-
Error Response:
-
Code: 409 CONFLICT
Content:
{
"Response": {
"Status": 409,
"Error": -2,
"Description": "Repeated UserName"
}
}
-
Sample Call:
$.ajax({
url: "/Register",
dataType: "json",
type : "POST",
201 : function(r) {
console.log(r);
}
});
Login User
Logs in with a json given user
-
URL
/Login
-
Method:
POST
-
URL Params
None
-
Data Params
{
"username":"Bob Smith",
"password":"secretPassword"
}
-
Success Response:
- Code: 200 OK
Content:
{
"Response": {
"Status": 200,
"Token": "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjJlZjM5NjQ0LTg1YjYtMTFlNy04Y2Q1LTAyNDJhYzExMDAwMiJ9.87Ok320Qdj6JQ_xS5cBngc1VcL2yuPvUnCSfYgv5qrEI1FBbcCHnoUdUtBGn3pCk0qYD_cWljaNnprHLwOPkKQ",
"Error": 1
}
}
-
Error Response:
-
Code: 404 NOT FOUND
Content:
{
"Response": {
"Status": 404,
"Error": -8,
"Description": "User not found"
}
}
-
Sample Call:
$.ajax({
url: "/Register",
dataType: "json",
type : "POST",
200 : function(r) {
console.log(r);
}
});
Validate Token
Validates a given token.
-
URL
/Token/isValid
-
Method:
POST
-
URL Params
None
-
Data Params
None
-
Headers
"Authorization":"eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImQxZmY1MDE4LTgyYjgtMTFlNy1hMGQ1LTAyNDJhYzExMDAwMiJ9.vwm1JhqfPhI6Vj-A4BubhaGyrSpGSKYQ246JSPQqd6lZBrkpuDrpYem79baUJPQDXoduw14j6x26KkK8wprzTg"
-
Success Response:
-
Error Response:
-
Code: 404 NOT FOUND
Content:
{
"Response": {
"Status": 404,
"Error": -7,
"Description": "The token is invalid"
}
}
-
Sample Call:
$.ajax({
url: "/Register",
dataType: "json",
type : "POST",
204 : function(r) {
console.log(r);
}
});
Logout User
Logs out with a json given user
-
URL
/Logout
-
Method:
POST
-
URL Params
None
-
Data Params
{
"username":"Bob Smith",
"password":"secretPassword"
}
-
Success Response:
-
Sample Call:
$.ajax({
url: "/Register",
dataType: "json",
type : "POST",
200 : function(r) {
console.log(r);
}
});
Error codes
As seen, in all responses have an error code. Those are for a quick check of the response apart from the http response code. Here are the codes:
| Code |
Description |
| 1 |
Ok |
| -1 |
Unknown error |
| -2 |
Repeated User Name |
| -3 |
Repeated User Email |
| -4 |
Database error |
| -5 |
Json Error |
| -6 |
No token provided |
| -7 |
Invalid token |
| -8 |
User Not Found |
Built With
- MySQL - The database engine.
- mytap - The test framework.
Contributing
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
Versioning
We use SemVer for versioning. For the versions available, see the tags on this repository.
Integrations
- Google
- Github
- Twitter
- Facebook
Authors
License
This project is licensed under the MIT License - see the LICENSE.md file for details