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: No content
-
Error Response:
-
Code: 409 CONFLICT
Content:
{
"error": {
"status": 409,
"error": "FIELDS_REPEATED",
"description": "One or more fields already exist",
"fields": {
"email": "An account already exists with this email",
"username": "An account already exists with this 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": "OK",
"token": "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImQxZmY1MDE4LTgyYjgtMTFlNy1hMGQ1LTAyNDJhYzExMDAwMiJ9.vwm1JhqfPhI6Vj-A4BubhaGyrSpGSKYQ246JSPQqd6lZBrkpuDrpYem79baUJPQDXoduw14j6x26KkK8wprzTg",
"error": ""
}
}
-
Error Response:
-
Code: 404 NOT FOUND
Content:
{
"response": {
"status": "Incorrect user or password",
"token": "",
"error": ""
}
}
-
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:
- Code: 204 NO CONTENT
Content:
None
-
Error Response:
-
Code: 404 NOT FOUND
Content:
None
-
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:
- Code: 204 NO CONTENT
Content:
None
-
Error Response:
-
Code: 404 NOT FOUND
Content:
{
"response": {
"status": "Incorrect user or password",
"token": "",
"error": ""
}
}
-
Sample Call:
$.ajax({
url: "/Register",
dataType: "json",
type : "POST",
201 : function(r) {
console.log(r);
}
});
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