Exemple #1
0
func Signin(c web.C, w http.ResponseWriter, r *http.Request) {
	session := controllers.Session{}
	ipAddress, _, _ := net.SplitHostPort(r.RemoteAddr)
	err := session.CreateSession(r.FormValue("login"), r.FormValue("password"), ipAddress)
	if session.Token != "" {
		helpers.RenderJSON(w, session, http.StatusOK)
	} else {
		helpers.RenderJSON(w, err, http.StatusOK)
	}
}
Exemple #2
0
func GetOwnPosts(c web.C, w http.ResponseWriter, r *http.Request) {
	post := controllers.Post{}

	post.Token = r.FormValue("token")
	err := post.GetOwnPosts()
	if err.Status == "KO" {
		helpers.RenderJSON(w, err, http.StatusOK)
	} else {
		post.PostsModel.Status = "OK"
		helpers.RenderJSON(w, post.PostsModel, http.StatusOK)
	}
}
Exemple #3
0
func GetPost(c web.C, w http.ResponseWriter, r *http.Request) {
	post := controllers.Post{}

	post.Id, _ = strconv.Atoi(c.URLParams["id"])
	post.Token = r.FormValue("token")
	err := post.GetPostById()
	if err.Status == "KO" {
		helpers.RenderJSON(w, err, http.StatusOK)
	} else {
		post.PostModel.Status = "OK"
		helpers.RenderJSON(w, post.PostModel, http.StatusOK)
	}
}
Exemple #4
0
func DeletePost(c web.C, w http.ResponseWriter, r *http.Request) {
	post := controllers.Post{}

	post.Id, _ = strconv.Atoi(c.URLParams["id"])
	post.Token = r.FormValue("token")
	helpers.RenderJSON(w, post.DeletePost(), http.StatusOK)
}
Exemple #5
0
func CreatePost(c web.C, w http.ResponseWriter, r *http.Request) {
	post := controllers.Post{}

	post.Title = r.FormValue("title")
	post.Content = r.FormValue("content")
	post.Token = r.FormValue("token")
	post.Important, _ = strconv.Atoi(r.FormValue("important"))
	helpers.RenderJSON(w, post.CreatePost(), http.StatusOK)
}
Exemple #6
0
func Comfirmation(c web.C, w http.ResponseWriter, r *http.Request) {
	user := controllers.User{}
	user.VerifiedToken = r.FormValue("verifiedtoken")
	errr := user.ComfirmAccount()
	if strings.Compare(errr.Status, "KO") == 0 {
		helpers.RenderJSON(w, errr, http.StatusOK)
	} else {
		helpers.RenderOk(w)
	}
}
Exemple #7
0
func Signup(c web.C, w http.ResponseWriter, r *http.Request) {
	user := controllers.User{}
	helpers.RenderJSON(w, user.CreateAccount(r.FormValue("login"), r.FormValue("email"), r.FormValue("password"), r.FormValue("password2")), http.StatusOK)
}