-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
805f491
commit 5904cdb
Showing
12 changed files
with
309 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package webapi | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/gorilla/sessions" | ||
) | ||
|
||
// adminPage is the handler for "GET /admin". The admin template will be | ||
// rendered if the current session is authenticated as an admin, otherwise the | ||
// login template will be rendered. | ||
func adminPage(c *gin.Context) { | ||
session := c.MustGet("session").(*sessions.Session) | ||
admin := session.Values["admin"] | ||
|
||
if admin == nil { | ||
c.HTML(http.StatusUnauthorized, "login.html", gin.H{}) | ||
return | ||
} | ||
|
||
tickets, err := db.GetAllTickets() | ||
if err != nil { | ||
log.Errorf("GetAllTickets error: %v", err) | ||
c.String(http.StatusInternalServerError, "Error getting tickets from db") | ||
return | ||
} | ||
|
||
c.HTML(http.StatusOK, "admin.html", gin.H{ | ||
"Tickets": tickets, | ||
}) | ||
} | ||
|
||
// adminLogin is the handler for "POST /admin". If a valid password is provided, | ||
// the current session will be authenticated as an admin. | ||
func adminLogin(c *gin.Context) { | ||
password := c.PostForm("password") | ||
|
||
if password != cfg.AdminPass { | ||
log.Warnf("Failed login attempt from %s", c.ClientIP()) | ||
c.HTML(http.StatusUnauthorized, "login.html", gin.H{ | ||
"IncorrectPassword": true, | ||
}) | ||
return | ||
} | ||
|
||
setAdminStatus(true, c) | ||
} | ||
|
||
// adminLogout is the handler for "POST /admin/logout". The current session will | ||
// have its admin authentication removed. | ||
func adminLogout(c *gin.Context) { | ||
setAdminStatus(nil, c) | ||
} | ||
|
||
// setAdminStatus stores the authentication status of the current session. | ||
func setAdminStatus(admin interface{}, c *gin.Context) { | ||
session := c.MustGet("session").(*sessions.Session) | ||
session.Values["admin"] = admin | ||
err := session.Save(c.Request, c.Writer) | ||
if err != nil { | ||
log.Errorf("Error saving session: %v", err) | ||
c.String(http.StatusInternalServerError, "Error saving session") | ||
return | ||
} | ||
|
||
c.Redirect(http.StatusFound, "/admin") | ||
c.Abort() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{{ template "header" . }} | ||
|
||
<form action="/admin/logout" method="post"> | ||
<button type="submit">Logout</button> | ||
</form> | ||
|
||
<table> | ||
<tr> | ||
<td>Hash</td> | ||
<td>CommitmentAddress</td> | ||
<td>FeeAddressIndex</td> | ||
<td>FeeAddress</td> | ||
<td>FeeAmount</td> | ||
<td>FeeExpiration</td> | ||
<td>Confirmed</td> | ||
<td>VoteChoices</td> | ||
<td>VotingWIF</td> | ||
<td>FeeTxHex</td> | ||
<td>FeeTxHash</td> | ||
<td>FeeConfirmed</td> | ||
</tr> | ||
{{ range .Tickets }} | ||
<tr> | ||
<td>{{ printf "%.10s" .Hash }}...</td> | ||
<td>{{ printf "%.10s" .CommitmentAddress }}...</td> | ||
<td>{{ printf "%d" .FeeAddressIndex }}</td> | ||
<td>{{ printf "%.10s" .FeeAddress }}...</td> | ||
<td>{{ printf "%f" .FeeAmount }}</td> | ||
<td>{{ printf "%d" .FeeExpiration }}</td> | ||
<td>{{ printf "%t" .Confirmed }}</td> | ||
<td>{{ printf "%.10s" .VoteChoices }}...</td> | ||
<td>{{ printf "%.10s" .VotingWIF }}...</td> | ||
<td>{{ printf "%.10s" .FeeTxHex }}...</td> | ||
<td>{{ printf "%.10s" .FeeTxHash }}...</td> | ||
<td>{{ printf "%t" .FeeConfirmed }}</td> | ||
</tr> | ||
{{ end }} | ||
</table> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{{define "header"}} | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta charset="utf-8"> | ||
|
||
<title>vspd</title> | ||
|
||
<link rel="stylesheet" type="text/css" href="/public/css/fonts.css" /> | ||
<link rel="stylesheet" type="text/css" href="/public/css/vspd.css" /> | ||
|
||
<!-- Custom favicon --> | ||
<!-- Apple PWA --> | ||
<link rel="apple-touch-icon" sizes="57x57" href="/public/images/favicon/apple-touch-icon-57x57.png?v=gT6Mc"> | ||
<link rel="apple-touch-icon" sizes="60x60" href="/public/images/favicon/apple-touch-icon-60x60.png?v=gT6Mc"> | ||
<link rel="apple-touch-icon" sizes="72x72" href="/public/images/favicon/apple-touch-icon-72x72.png?v=gT6Mc"> | ||
<link rel="apple-touch-icon" sizes="76x76" href="/public/images/favicon/apple-touch-icon-76x76.png?v=gT6Mc"> | ||
<link rel="apple-touch-icon" sizes="114x114" href="/public/images/favicon/apple-touch-icon-114x114.png?v=gT6Mc"> | ||
<link rel="apple-touch-icon" sizes="120x120" href="/public/images/favicon/apple-touch-icon-120x120.png?v=gT6Mc"> | ||
<link rel="apple-touch-icon" sizes="144x144" href="/public/images/favicon/apple-touch-icon-144x144.png?v=gT6Mc"> | ||
<link rel="apple-touch-icon" sizes="152x152" href="/public/images/favicon/apple-touch-icon-152x152.png?v=gT6Mc"> | ||
<link rel="apple-touch-icon" sizes="180x180" href="/public/images/favicon/apple-touch-icon-180x180.png?v=gT6Mc"> | ||
|
||
<!-- Browser --> | ||
<link rel="icon" href="/public/images/favicon/favicon.ico?v=gT6Mc"> | ||
<link rel="icon" href="/public/images/favicon/favicon-32x32.png?v=gT6Mc" type="image/png" sizes="32x32"> | ||
<link rel="icon" href="/public/images/favicon/favicon-16x16.png?v=gT6Mc" type="image/png" sizes="16x16"> | ||
|
||
<!-- Android PWA --> | ||
<link rel="manifest" href="/public/images/favicon/manifest.json?v=gT6Mc"> | ||
|
||
<!-- Safari --> | ||
<link rel="mask-icon" href="/public/images/favicon/safari-pinned-tab.svg?v=gT6Mc" color="#091440"> | ||
|
||
<!-- Windows PWA --> | ||
<meta name="msapplication-TileColor" content="#091440"> | ||
<meta name="msapplication-TileImage" content="/public/images/favicon/mstile-144x144.png?v=gT6Mc"> | ||
<meta name="msapplication-config" content="/public/images/favicon/browserconfig.xml?v=gT6Mc"> | ||
<!-- End custom favicon --> | ||
</head> | ||
|
||
<body> | ||
<img src="/public/images/decred-logo.svg" /> | ||
{{end}} |
Oops, something went wrong.