Skip to content
Snippets Groups Projects
Commit ba8f7f28 authored by Philipp Hochkamp's avatar Philipp Hochkamp
Browse files

Merge branch 'fix-20-solve-count' into 'master'

added solvecount to detail view

Closes #20

See merge request !17
parents 432b3029 8e3e05b8
No related branches found
No related tags found
1 merge request!17added solvecount to detail view
Pipeline #1822 passed with warnings
...@@ -3,9 +3,9 @@ package wtfd ...@@ -3,9 +3,9 @@ package wtfd
import ( import (
"errors" "errors"
"fmt" "fmt"
"golang.org/x/crypto/bcrypt"
"github.com/go-xorm/xorm" "github.com/go-xorm/xorm"
_ "github.com/mattn/go-sqlite3" // needed for xorm _ "github.com/mattn/go-sqlite3" // needed for xorm
"golang.org/x/crypto/bcrypt"
"os" "os"
"xorm.io/core" "xorm.io/core"
) )
...@@ -63,7 +63,6 @@ func Login(username, passwd string) error { ...@@ -63,7 +63,6 @@ func Login(username, passwd string) error {
} }
// NewUser creates a new user object // NewUser creates a new user object
func NewUser(name, password, displayname string) (User, error) { func NewUser(name, password, displayname string) (User, error) {
if Contains(name, displayname) { if Contains(name, displayname) {
...@@ -78,13 +77,13 @@ func NewUser(name, password, displayname string) (User, error) { ...@@ -78,13 +77,13 @@ func NewUser(name, password, displayname string) (User, error) {
return User{Name: name, Hash: hash, DisplayName: displayname}, nil return User{Name: name, Hash: hash, DisplayName: displayname}, nil
} }
// Contains looks if a username is in the datenbank // Contains looks if a username is in the datenbank
func Contains(username, displayname string) bool { func Contains(username, displayname string) bool {
count, _ := ormUserExists(User{Name: username, DisplayName: displayname}) count, _ := ormUserExists(User{Name: username, DisplayName: displayname})
return count return count
} }
// Get gets username based on username // Get gets username based on username
func Get(username string) (User, error) { func Get(username string) (User, error) {
user, err := ormLoadUser(username) user, err := ormLoadUser(username)
...@@ -148,6 +147,17 @@ func ormNewUser(user User) error { ...@@ -148,6 +147,17 @@ func ormNewUser(user User) error {
return err return err
} }
// ormGetSolveCount returns the number of solves for the Challenge chall
func ormGetSolveCount(chall Challenge) int64 {
count, err := engine.Where("ChallengeName = ?", chall.Name).Count(_ORMChallengesByUser{})
if err != nil {
return 0
}
return count
}
// Update existing user record (user.Name) with other values from user // Update existing user record (user.Name) with other values from user
// Solved challenges WON'T be updated (refer to ormChallengeSolved) // Solved challenges WON'T be updated (refer to ormChallengeSolved)
func ormUpdateUser(user User) error { func ormUpdateUser(user User) error {
......
...@@ -332,7 +332,7 @@ func detailview(w http.ResponseWriter, r *http.Request) { ...@@ -332,7 +332,7 @@ func detailview(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusBadRequest) w.WriteHeader(http.StatusBadRequest)
return return
} }
_, _ = fmt.Fprintf(w, "%s", chall.Description) _, _ = fmt.Fprintf(w, "%s<br><p>Solves: %d</p>", chall.Description, ormGetSolveCount(*chall))
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment