rest

package
v0.0.0-...-8af4378 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2014 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrCodeInvalidCredential float32 = 1.2
	ErrCodePwdMismatch       float32 = 1.3
	ErrCodeInvlaidPwd        float32 = 1.4
	ErrCodeDupEmail          float32 = 1.5
	ErrCodeInvalidEmail      float32 = 1.6
	ErrCodeInvalidId         float32 = 1.7
	ErrCodeNotExistId        float32 = 1.9
)
View Source
const (
	ErrCodeInvalidInput     float32 = 1.0
	ErrCodeInvalidGrantType float32 = 1.1
)

Variables

View Source
var (
	OnlineThreshold = time.Hour
)

Functions

func ActiveAccount

func ActiveAccount(rw http.ResponseWriter, req *http.Request)

ActiveAccount handle active request by using confirm code.

Example Request:

GET /active/some-kind-of-ID?code=secure-random-base64-string

Example Success Response:

{
  "Message":"Account activated"
}

func GetToken

func GetToken(rw http.ResponseWriter, req *http.Request)

GetToken handle both POST and GET method to obtain login token. Note that only "password" support for "grant_type" right now.

Example Request:

GET /tokens?grant_type=password&email=nguyen@open-vn.org&password=xxxxxxxxx

Example Success Response:

{
  "User": {...}, // auth.User object with empty Pwd, OldPwd, ConfirmCodes
  "ExpiredOn": "2009-11-10T23:00:00Z",
  "AccessToken": "afE.....MNWt-HfVYcFOs7w_ryOzvsYA==" // a secure random base64 encoded string
}

func Handler

func Handler(router *mux.Router)

func PasswordUpdate

func PasswordUpdate(rw http.ResponseWriter, req *http.Request)

PasswordUpdate handle the request for changin user password. its require 'manage_user' permission to change other's password.

Example Request Body:

POST /profile/some-kind-of-ID/change-password
{
  "Pwd": "xxxxxxxxx",
  "NewPwd": "yyyyyyyyy",
  "NewPwdRepeat": "yyyyyyyyy"
}

Example Success Response:

{
  "Message":"Password for user  has been updated."
}

func SignUp

func SignUp(rw http.ResponseWriter, req *http.Request)

SignUp handle the request for account sign-up. The handler will check the email and password format. If success it will send an email and immediately return a 202 status code.

Example Request Body:

POST /signup
{
  "Email": "nguyen@open-vn.org",
  "Pwd": "xxxxxxxxx",
  "PwdRepeat": "xxxxxxxxx"
}

Example Success Response:

{
  "Message":"email sent to nguyen@open-vn.org"
}

func UserInfoDetail

func UserInfoDetail(rw http.ResponseWriter, req *http.Request)

UserInfoDetail handle the request for getting user account info.

Example Request Body:

GET /profile/some-kind-of-ID/info

Example Success Response

{
  "FirstName": "Cao Nguyên"
  ...//other feilds of auth,UserInfo struct
}

func UserInfoUpdate

func UserInfoUpdate(rw http.ResponseWriter, req *http.Request)

UserInfoUpdate handle the reuqest for update user infomation. Its require 'manage_user' to change other's infomation.

Example Request Body:

PUT /profile/some-kind-of-ID/info
{
  "FirstName": "Cao Nguyên"
  ...//other feilds of auth,UserInfo struct
}

func UserList

func UserList(rw http.ResponseWriter, req *http.Request)

Types

type LoginInfo

type LoginInfo struct {
	User        *auth.User
	ExpiredOn   time.Time
	AccessToken string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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