controllers

package
v0.0.0-...-5c8e363 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 2, 2020 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Authenticate = func(w http.ResponseWriter, r *http.Request) {
	acc := &models.Account{}
	err := json.NewDecoder(r.Body).Decode(acc)
	if err != nil {
		u.Respond(w, u.Message(false, err.Error()))
		return
	}

	if acc.Email == "" {
		if acc.Username == "" {
			u.Respond(w, u.Message(false, "Both username and password missing"))
		}

		res := models.LoginUsername(acc.Username, acc.Password)
		u.Respond(w, res)
		return
	}

	res := models.Login(acc.Email, acc.Password)
	u.Respond(w, res)
}

* * @api {post} /api/users/login * @apiName Log into user account * @apiGroup Authorization * * @apiPermission anyone * @apiParam {string} [email] User's email address * @apiParam {string} [username] Username * @apiParam {string{8..60}} password Password to use for this account * @apiParamExample {json} request-example * * { * "email": "john.doe@example.com", * "username": "JohnDoe", * "password": "password123" * } * *

View Source
var CreateAccount = func(w http.ResponseWriter, r *http.Request) {
	acc := &models.Account{}
	err := json.NewDecoder(r.Body).Decode(acc)
	if err != nil {
		u.Respond(w, u.Message(false, err.Error()))
		return
	}

	res := acc.Create()
	u.Respond(w, res)
}

* * @api {post} /api/users/new * @apiName Create a new user account * @apiGroup Authorization * * @apiPermission anyone * @apiParam {string} email User's email address * @apiParam {string} username Username * @apiParam {string{8..60}} password Password to use for this account * @apiParamExample {json} request-example * * { * "email": "john.doe@example.com", * "username": "JohnDoe", * "password": "password123" * } * *

View Source
var CreateNote = func(w http.ResponseWriter, r *http.Request) {
	note := &models.Notes{}
	err := json.NewDecoder(r.Body).Decode(note)
	if err != nil {
		u.Respond(w, u.Message(false, err.Error()))
		return
	}
	res := note.SaveNote(r.Context())
	u.Respond(w, res)
}

* * @api {post} /api/notes/save * @apiName Create or update a note * @apiGroup Notes * * @apiPermission Logged-in users * * @apiParam {number} note_id The note's ID * @apiParam {string} title The note's title * @apiParam {string} content The note's content * @apiParam {boolean} is_starred Whether the note is starred or not * @apiParam {number} date Date of note creation * @apiParam {number} color The color of the note * @apiParam {string} image_path Image path * @apiParam {boolean} is_list Whether the note contains a list or not * @apiParam {string} list_parse_string List parse string * @apiParam {string} reminders Reminders associated with the note * @apiParam {boolean} hide_content Whether to hide the note or not * @apiParam {string} pin Pin * @apiParam {string} password Password to lock the note with * @apiParam {boolean} is_deleted Is deleted or not * @apiParam {boolean} is_archived Is archived or not * @apiParamExample {json} request-example * * { * "note_id": 5, * "title": "Sample note 2", * "content": "This is a sample note 2", * "is_starred": true, * "date": 20191211, * "color": 4, * "image_path": "abcd", * "is_list": false, * "list_parse_string": "abcd", * "reminders": "abcd", * "hide_content": false, * "pin": "smth", * "password": "password123", * "is_deleted": false, * "is_archived": false * } * * @apiHeader {string} Authorization JWT token associated with user account * @apiHeaderExample {string} Header-Example: * eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySWQiOjV9.FTIhjfCLND1L-hvhgH9_TC_P7MbGQnjnNnFOjJL8Q1k * *

View Source
var DeleteAccount = func(w http.ResponseWriter, r *http.Request) {
	res := models.DeleteAccount(r.Context())
	u.Respond(w, res)
}

* * @api {post} /api/users/delete * @apiName Delete a user account * @apiGroup Authorization * * @apiPermission Logged-in users * @apiHeader {string} Authorization JWT token associated with user account * @apiHeaderExample {string} Header-Example: * eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySWQiOjV9.FTIhjfCLND1L-hvhgH9_TC_P7MbGQnjnNnFOjJL8Q1k * *

View Source
var DeleteAllNotes = func(w http.ResponseWriter, r *http.Request) {
	res := models.DeleteAllNotes(r.Context())
	u.Respond(w, res)
}

* * @api {post} /api/notes/deleteall * @apiName Delete all saved notes for a user * @apiGroup Notes * * @apiPermission Logged-in users * * @apiHeader {string} Authorization JWT token associated with user account * @apiHeaderExample {string} Header-Example: * eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySWQiOjV9.FTIhjfCLND1L-hvhgH9_TC_P7MbGQnjnNnFOjJL8Q1k * *

View Source
var DeleteNote = func(w http.ResponseWriter, r *http.Request) {
	note := &models.Notes{}
	err := json.NewDecoder(r.Body).Decode(note)
	if err != nil {
		u.Respond(w, u.Message(false, err.Error()))
		return
	}
	res := models.DeleteNote(r.Context(), note.NoteID)
	u.Respond(w, res)
}

* * @api {post} /api/notes/delete * @apiName Delete a saved note * @apiGroup Notes * * @apiPermission Logged-in users * * @apiParam {number} note_id The note's ID * @apiParamExample {json} request-example * * { * "note_id": 5, * } * * @apiHeader {string} Authorization JWT token associated with user account * @apiHeaderExample {string} Header-Example: * eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySWQiOjV9.FTIhjfCLND1L-hvhgH9_TC_P7MbGQnjnNnFOjJL8Q1k * *

View Source
var ListNotes = func(w http.ResponseWriter, r *http.Request) {
	res := models.ListNotes(r.Context())
	u.Respond(w, res)
}

* * @api {get} /api/notes/list * @apiName List notes associated with a user * @apiGroup Notes * * @apiPermission Logged-in users * * @apiHeader {string} Authorization JWT token associated with user account * @apiHeaderExample {string} Header-Example: * eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySWQiOjV9.FTIhjfCLND1L-hvhgH9_TC_P7MbGQnjnNnFOjJL8Q1k * *

View Source
var UserInfo = func(w http.ResponseWriter, r *http.Request) {
	res := models.AccInfo(r.Context())
	u.Respond(w, res)
}

* * @api {get} /api/users/info * @apiName View info about user account * @apiGroup Authorization * * @apiPermission Logged-in users * @apiHeader {string} Authorization JWT token associated with user account * @apiHeaderExample {string} Header-Example: * eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySWQiOjV9.FTIhjfCLND1L-hvhgH9_TC_P7MbGQnjnNnFOjJL8Q1k * *

Functions

func GetStats

func GetStats(w http.ResponseWriter, r *http.Request)

func ModifyPassword

func ModifyPassword(w http.ResponseWriter, r *http.Request)

* * @api {post} /api/users/manage/password * @apiName Modify account's password * @apiGroup Authorization * * @apiPermission Logged-in users * * @apiParam {string} password The new password * @apiParamExample {json} request-example * * { * "password": "password123", * } * * @apiHeader {string} Authorization JWT token associated with user account * @apiHeaderExample {string} Header-Example: * eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySWQiOjV9.FTIhjfCLND1L-hvhgH9_TC_P7MbGQnjnNnFOjJL8Q1k * *

func ModifyUsername

func ModifyUsername(w http.ResponseWriter, r *http.Request)

* * @api {post} /api/users/manage/username * @apiName Modify account's username * @apiGroup Authorization * * @apiPermission Logged-in users * * @apiParam {string} email The user's email * @apiParam {string} username The new username * @apiParamExample {json} request-example * * { * "email": "john.doe@example.com", * "username": "JohnDoe", * } * * @apiHeader {string} Authorization JWT token associated with user account * @apiHeaderExample {string} Header-Example: * eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySWQiOjV9.FTIhjfCLND1L-hvhgH9_TC_P7MbGQnjnNnFOjJL8Q1k * *

func SaveImage

func SaveImage(w http.ResponseWriter, r *http.Request)

* * @api {post} /api/users/manage/image * @apiName Modify account's password * @apiGroup Authorization * * @apiPermission Logged-in users * * @apiParam {string} image_url The url to the user's profile image * @apiParamExample {json} request-example * * { * "image_url": "https://example.com/1234567", * } * * @apiHeader {string} Authorization JWT token associated with user account * @apiHeaderExample {string} Header-Example: * eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySWQiOjV9.FTIhjfCLND1L-hvhgH9_TC_P7MbGQnjnNnFOjJL8Q1k * *

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL