fea: support get openvpn file from user

This commit is contained in:
Daniel Ding
2023-12-27 21:24:02 +08:00
parent dd05f95017
commit 9909380092
8 changed files with 82 additions and 38 deletions

View File

@@ -72,14 +72,25 @@ func (h User) Del(w http.ResponseWriter, r *http.Request) {
ResponseMsg(w, 0, "")
}
func UserCheck(user, pass string) error {
model := &models.User{
Name: user,
Password: pass,
}
if _, err := cache.User.Check(model); err == nil {
return nil
} else {
return err
}
}
func (h User) Check(w http.ResponseWriter, r *http.Request) {
user := &schema.User{}
if err := GetData(r, user); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
model := models.SchemaToUserModel(user)
if _, err := cache.User.Check(model); err == nil {
if err := UserCheck(user.Name, user.Password); err == nil {
ResponseMsg(w, 0, "success")
} else {
http.Error(w, err.Error(), http.StatusUnauthorized)