// TODO: replace with simple ResponseInfo containing userid
typeprofileDatastruct{
baseTemplateData
UserIDint
}
funcuserProfile(c*gin.Context){
var(
userIDint
usernamestring
privilegesuint64
)
ctx:=getContext(c)
u:=c.Param("user")
if_,err:=strconv.Atoi(u);err!=nil{
err:=db.QueryRow("SELECT id, username, privileges FROM users WHERE username = ? AND "+ctx.OnlyUserPublic()+" LIMIT 1",u).Scan(&userID,&username,&privileges)
iferr!=nil&&err!=sql.ErrNoRows{
c.Error(err)
}
}else{
err:=db.QueryRow(`SELECT id, username, privileges FROM users WHERE id = ? AND `+ctx.OnlyUserPublic()+` LIMIT 1`,u).Scan(&userID,&username,&privileges)
switch{
caseerr==nil:
caseerr==sql.ErrNoRows:
err:=db.QueryRow(`SELECT id, username, privileges FROM users WHERE username = ? AND `+ctx.OnlyUserPublic()+` LIMIT 1`,u).Scan(&userID,&username,&privileges)
iferr!=nil&&err!=sql.ErrNoRows{
c.Error(err)
}
default:
c.Error(err)
}
}
data:=new(profileData)
data.UserID=userID
deferresp(c,200,"profile.html",data)
ifdata.UserID==0{
data.TitleBar="User not found"
data.Messages=append(data.Messages,warningMessage{T(c,"That user could not be found.")})
err:=db.QueryRow("SELECT id, username, privileges FROM users WHERE username = ? AND "+ctx.OnlyUserPublic()+" LIMIT 1",u).Scan(&userID,&username,&privileges)
iferr!=nil&&err!=sql.ErrNoRows{
c.Error(err)
}
}else{
err:=db.QueryRow(`SELECT id, username, privileges FROM users WHERE id = ? AND `+ctx.OnlyUserPublic()+` LIMIT 1`,u).Scan(&userID,&username,&privileges)
switch{
caseerr==nil:
caseerr==sql.ErrNoRows:
err:=db.QueryRow(`SELECT id, username, privileges FROM users WHERE username = ? AND `+ctx.OnlyUserPublic()+` LIMIT 1`,u).Scan(&userID,&username,&privileges)
iferr!=nil&&err!=sql.ErrNoRows{
c.Error(err)
}
default:
c.Error(err)
}
}
data:=new(profileData)
data.UserID=userID
deferresp(c,200,"profile_relax.html",data)
ifdata.UserID==0{
data.TitleBar="User not found"
data.Messages=append(data.Messages,warningMessage{T(c,"That user could not be found.")})
err:=db.QueryRow("SELECT id, username, privileges FROM users WHERE username = ? AND "+ctx.OnlyUserPublic()+" LIMIT 1",u).Scan(&userID,&username,&privileges)
iferr!=nil&&err!=sql.ErrNoRows{
c.Error(err)
}
}else{
err:=db.QueryRow(`SELECT id, username, privileges FROM users WHERE id = ? AND `+ctx.OnlyUserPublic()+` LIMIT 1`,u).Scan(&userID,&username,&privileges)
switch{
caseerr==nil:
caseerr==sql.ErrNoRows:
err:=db.QueryRow(`SELECT id, username, privileges FROM users WHERE username = ? AND `+ctx.OnlyUserPublic()+` LIMIT 1`,u).Scan(&userID,&username,&privileges)
iferr!=nil&&err!=sql.ErrNoRows{
c.Error(err)
}
default:
c.Error(err)
}
}
data:=new(profileData)
data.UserID=userID
deferresp(c,200,"profile_auto.html",data)
ifdata.UserID==0{
data.TitleBar="User not found"
data.Messages=append(data.Messages,warningMessage{T(c,"That user could not be found.")})