user.go 414 B

123456789101112131415161718
  1. package service
  2. import (
  3. "cc-officialweb/models"
  4. "cc-officialweb/utils"
  5. "fmt"
  6. )
  7. func Login(user models.User) string {
  8. fmt.Println("user:", user.Username, user.Password)
  9. pwd := utils.MD5(user.Password)
  10. tx := utils.DB.Where("username = ?", user.Username).Where("password = ?", pwd).First(&user)
  11. if tx.RowsAffected > 0 {
  12. token, _ := utils.CreateToken(user.ID, user.Username)
  13. return token
  14. }
  15. return ""
  16. }