// CloseSession takes a digits auth and converts it into internal auth func CloseSession(c *echo.Context) (int, interface{}) { hauth, ok := c.Get("habloAuth").(*models.HabloAuth) if !ok { return msg.Forbidden("must include an authorization") } log.Printf("Awaiting for [HabloAuth = %s] deletion", hauth.ID.Hex()) err := mangos.Execute(collection, func(c *mgo.Collection) error { return c.RemoveId(hauth.ID) }) if err != nil { log.Printf("Cannot remove [HabloAuth = %s]: %s", hauth.ID.Hex(), err) return msg.InternalError(err) } log.Printf("Removed [HabloAuth = %s]", hauth.ID.Hex()) return msg.Ok("see you") }
// Delete removes the indicated object from database. // ID must be the same as session. func Delete(c *echo.Context) (int, interface{}) { var err error reqid, _ := strconv.ParseInt(c.Param("id"), 10, 64) attid, _ := c.Get("digitsID").(int64) if reqid == attid { // Execute delete log.Printf("Awaiting for [Profile = %d] delete", reqid) err = mangos.Execute(collection, func(c *mgo.Collection) error { return c.RemoveId(reqid) }) if err != nil { log.Printf("Cannot delete [Profile = %d]: %s", reqid, err) return msg.InternalError(err) } log.Printf("Deleted [Profile = %d]", reqid) return msg.Ok("deleted") } return msg.Forbidden("the id does not belongs to user") }