package service

import (
	"cc-officialweb/models"
	"cc-officialweb/utils"
	"fmt"
)

func Login(user models.User) string {
	fmt.Println("user:", user.Username, user.Password)
	pwd := utils.MD5(user.Password)
	tx := utils.DB.Where("username = ?", user.Username).Where("password = ?", pwd).First(&user)
	if tx.RowsAffected > 0 {
		token, _ := utils.CreateToken(user.ID, user.Username)
		return token
	}
	return ""
}
