controllers

package
v0.0.0-...-94d3027 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CreateUser = func(w http.ResponseWriter, r *http.Request) {
	account := &models.Account{}

	err := json.NewDecoder(r.Body).Decode(account)

	if err != nil {
		utils.Respond(w, utils.Message(false, "Invalid info: "+err.Error()))
		return
	}

	utils.Respond(w, account.Create())
}
View Source
var Login = func(w http.ResponseWriter, r *http.Request) {
	email := utils.GetRequestParam(r, "email")

	pwd := utils.GetRequestParam(r, "password")

	if email == "" || pwd == "" {
		utils.Respond(w, utils.Message(false, "Invalid request param, email: "+email))
		return
	}

	utils.Respond(w, models.Login(email, pwd))
}
View Source
var Me = func(w http.ResponseWriter, r *http.Request) {
	value := r.Context().Value("user")

	fmt.Println("Context.user", value)

	userId, ok := value.(uint)

	if !ok {
		utils.Respond(w, utils.Message(false, "Invalid userId: "+string(userId)))
		return
	}

	account := models.GetUser(userId)

	if account == nil {
		utils.Respond(w, utils.Message(false, "User not found"))
		return
	}

	message := utils.MessageWithData(true, "Success", account)

	utils.Respond(w, message)
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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