func ProcessActions(c *gin.Context) { pretty.Println("In Process Actions") var action Action if c.BindJSON(&action) == nil { c.JSON(http.StatusOK, action) } else { c.JSON(http.StatusNotFound, gin.H{"status": "not found"}) } }
// ProcessLogin allow peeps to login func ProcessLogin(c *gin.Context) { var login Login if c.BindJSON(&login) == nil { pretty.Println(login) user, err := models.FindUserByEmail(login.Email) if user.ID.Valid() && err == nil { goodToGo := false goodToGo = ComputeHmac256(login.Password, getSecret(user.Salt)) == user.HashedPassword if !goodToGo { // if we cannot verify hmac 256 it maybe an old user account using the old style passwords, let us verify and update if ComputeSHA1(login.Password, user.Salt) == user.HashedPassword { go user.SetPassword(ComputeHmac256(login.Password, getSecret(user.Salt))) goodToGo = true } } if goodToGo { session, err := GlobalSessions.SessionStart(c.Writer, c.Request) defer session.SessionRelease(c.Writer) if err != nil { fmt.Println("error starting session: ", err) c.JSON(http.StatusForbidden, gin.H{"status": "Forbidden"}) return } session.Set("createTime", time.Now().Unix()) session.Set("email", login.Email) t := Token() session.Set("token", t) fmt.Println("set session to ", session.Get("email"), session.Get("token"), session.SessionID()) fmt.Println(user) if user.Customers == nil { customer, err := models.FindCustomerByName("eStratEx") if err != nil { fmt.Println("Error getting customer", err) } else { user.Customers = append(user.Customers, customer.ID) go func() { user.Update() }() } } c.JSON(http.StatusOK, gin.H{"status": "OK", "token": t, "createTime": session.Get("createTime")}) return } c.JSON(http.StatusForbidden, gin.H{"status": "Forbidden"}) } else { c.JSON(http.StatusNotFound, gin.H{"status": "Not Found"}) } } else { c.JSON(http.StatusNotFound, gin.H{"status": "Not Found"}) } }