Ejemplo n.º 1
0
func (this *CCMoment) Post(c *gin.Context) {
	this.Load()
	err := momentHandler.AddMoment(c)
	if err != nil {
		util.RespondWithError(401, "Data insertion failed", c)
		return
	}
	fmt.Println("Data Inserted Successfully: ")

}
Ejemplo n.º 2
0
func (this *CCAuthHandler) TokenAuthMiddleware() gin.HandlerFunc {
	return func(c *gin.Context) {
		token := c.Request.FormValue("api_token")

		if token == "" {
			util.RespondWithError(401, "authentication token required", c)
			return
		}
		if token == os.Getenv("API_TOKEN") {
			c.Next()
		} else {
			if !this.CheckUserToken(token) {
				util.RespondWithError(401, "Invalid/expired auth token. Please login again", c)
				return
			} else {
				c.Next()
			}
		}
	}
}
Ejemplo n.º 3
0
func (this *CCAuthHandler) BasicAuth(c *gin.Context) {

	username := c.PostForm("username")
	password := c.PostForm("password")
	// password 		:= c.Query("password")

	fmt.Println("Username - ", username)
	fmt.Println("Password - ", password)
	token, success := this.Validate(username, password)
	if !success {
		util.RespondWithError(401, "Invalid Username or Password", c)
		return
	}
	util.RespondWithSuccess(200, "api_token", token, c)
	fmt.Println("Successfully Logged in")

}