mirror of
https://github.com/hrfee/jfa-go.git
synced 2025-01-07 17:00:11 +00:00
Compare commits
No commits in common. "32af107699e9ded9cc8db908c226a2294335d797" and "d9f878537280d4595cc14a95d454cff4c644a08e" have entirely different histories.
32af107699
...
d9f8785372
@ -65,7 +65,7 @@ builds:
|
|||||||
flags:
|
flags:
|
||||||
- -tags=tray
|
- -tags=tray
|
||||||
ldflags:
|
ldflags:
|
||||||
- -s -w -X main.version={{.Env.JFA_GO_VERSION}} -X main.commit={{.ShortCommit}} -X main.updater=binary -X main.cssVersion={{.Env.JFA_GO_CSS_VERSION}} -H=windowsgui
|
- -s -w -X main.version={{.Env.JFA_GO_VERSION}} -X main.commit={{.ShortCommit}} -X main.updater=binary -H=windowsgui
|
||||||
goos:
|
goos:
|
||||||
- windows
|
- windows
|
||||||
goarch:
|
goarch:
|
||||||
@ -77,7 +77,7 @@ builds:
|
|||||||
flags:
|
flags:
|
||||||
- -tags=tray
|
- -tags=tray
|
||||||
ldflags:
|
ldflags:
|
||||||
- -s -w -X main.version={{.Env.JFA_GO_VERSION}} -X main.commit={{.ShortCommit}} -X main.updater=binary -X main.cssVersion={{.Env.JFA_GO_CSS_VERSION}}
|
- -s -w -X main.version={{.Env.JFA_GO_VERSION}} -X main.commit={{.ShortCommit}} -X main.updater=binary
|
||||||
goos:
|
goos:
|
||||||
- linux
|
- linux
|
||||||
goarch:
|
goarch:
|
||||||
|
33
api.go
33
api.go
@ -368,15 +368,6 @@ func (app *appContext) newUser(req newUserDTO, confirmed bool) (f errorFunc, suc
|
|||||||
success = false
|
success = false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err := app.discord.ApplyRole(discordUser.ID)
|
|
||||||
if err != nil {
|
|
||||||
f = func(gc *gin.Context) {
|
|
||||||
app.err.Printf("%s: New user failed: Failed to set member role: %v", req.Code, err)
|
|
||||||
respond(401, "error", gc)
|
|
||||||
}
|
|
||||||
success = false
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var matrixUser MatrixUser
|
var matrixUser MatrixUser
|
||||||
@ -637,11 +628,6 @@ func (app *appContext) NewUser(gc *gin.Context) {
|
|||||||
var req newUserDTO
|
var req newUserDTO
|
||||||
gc.BindJSON(&req)
|
gc.BindJSON(&req)
|
||||||
app.debug.Printf("%s: New user attempt", req.Code)
|
app.debug.Printf("%s: New user attempt", req.Code)
|
||||||
if app.config.Section("captcha").Key("enabled").MustBool(false) && !app.verifyCaptcha(req.Code, req.CaptchaID, req.CaptchaText) {
|
|
||||||
app.info.Printf("%s: New user failed: Captcha Incorrect", req.Code)
|
|
||||||
respond(400, "errorCaptcha", gc)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if !app.checkInvite(req.Code, false, "") {
|
if !app.checkInvite(req.Code, false, "") {
|
||||||
app.info.Printf("%s New user failed: invalid code", req.Code)
|
app.info.Printf("%s New user failed: invalid code", req.Code)
|
||||||
respond(401, "errorInvalidCode", gc)
|
respond(401, "errorInvalidCode", gc)
|
||||||
@ -665,6 +651,11 @@ func (app *appContext) NewUser(gc *gin.Context) {
|
|||||||
respond(400, "errorNoEmail", gc)
|
respond(400, "errorNoEmail", gc)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if app.config.Section("captcha").Key("enabled").MustBool(false) && !verifyCaptcha(req.Captcha) {
|
||||||
|
app.info.Printf("%s: New user failed: Captcha Incorrect", req.Code)
|
||||||
|
respond(400, "errorCaptcha", gc)
|
||||||
|
return
|
||||||
|
}
|
||||||
f, success := app.newUser(req, false)
|
f, success := app.newUser(req, false)
|
||||||
if !success {
|
if !success {
|
||||||
f(gc)
|
f(gc)
|
||||||
@ -2034,20 +2025,6 @@ func (app *appContext) GetConfig(gc *gin.Context) {
|
|||||||
resp.Sections[sectName].Settings[settingName] = s
|
resp.Sections[sectName].Settings[settingName] = s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if discordEnabled {
|
|
||||||
r, err := app.discord.ListRoles()
|
|
||||||
if err == nil {
|
|
||||||
roles := make([][2]string, len(r)+1)
|
|
||||||
roles[0] = [2]string{"", "None"}
|
|
||||||
for i, role := range r {
|
|
||||||
roles[i+1] = role
|
|
||||||
}
|
|
||||||
s := resp.Sections["discord"].Settings["apply_role"]
|
|
||||||
s.Options = roles
|
|
||||||
resp.Sections["discord"].Settings["apply_role"] = s
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
resp.Sections["ui"].Settings["language-form"] = fl
|
resp.Sections["ui"].Settings["language-form"] = fl
|
||||||
resp.Sections["ui"].Settings["language-admin"] = al
|
resp.Sections["ui"].Settings["language-admin"] = al
|
||||||
resp.Sections["email"].Settings["language"] = el
|
resp.Sections["email"].Settings["language"] = el
|
||||||
|
@ -686,18 +686,6 @@
|
|||||||
"value": "",
|
"value": "",
|
||||||
"description": "Channel to invite new users to."
|
"description": "Channel to invite new users to."
|
||||||
},
|
},
|
||||||
"apply_role": {
|
|
||||||
"name": "Apply Role on connection",
|
|
||||||
"required": false,
|
|
||||||
"requires_restart": true,
|
|
||||||
"depends_true": "enabled",
|
|
||||||
"type": "select",
|
|
||||||
"options": [
|
|
||||||
["", "None"]
|
|
||||||
],
|
|
||||||
"value": "",
|
|
||||||
"description": "Add the selected role to a user when they sign up."
|
|
||||||
},
|
|
||||||
"language": {
|
"language": {
|
||||||
"name": "Language",
|
"name": "Language",
|
||||||
"required": false,
|
"required": false,
|
||||||
|
31
discord.go
31
discord.go
@ -18,7 +18,6 @@ type DiscordDaemon struct {
|
|||||||
guildID string
|
guildID string
|
||||||
serverChannelName, serverName string
|
serverChannelName, serverName string
|
||||||
users map[string]DiscordUser // Map of user IDs to users. Added to on first interaction, and loaded from app.storage.discord on start.
|
users map[string]DiscordUser // Map of user IDs to users. Added to on first interaction, and loaded from app.storage.discord on start.
|
||||||
roleID string
|
|
||||||
app *appContext
|
app *appContext
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,7 +38,6 @@ func newDiscordDaemon(app *appContext) (*DiscordDaemon, error) {
|
|||||||
verifiedTokens: map[string]DiscordUser{},
|
verifiedTokens: map[string]DiscordUser{},
|
||||||
users: map[string]DiscordUser{},
|
users: map[string]DiscordUser{},
|
||||||
app: app,
|
app: app,
|
||||||
roleID: app.config.Section("discord").Key("apply_role").String(),
|
|
||||||
}
|
}
|
||||||
for _, user := range app.storage.discord {
|
for _, user := range app.storage.discord {
|
||||||
dd.users[user.ID] = user
|
dd.users[user.ID] = user
|
||||||
@ -113,35 +111,6 @@ func (d *DiscordDaemon) run() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListRoles returns a list of available (excluding bot and @everyone) roles in a guild as a list of containing an array of the guild ID and its name.
|
|
||||||
func (d *DiscordDaemon) ListRoles() (roles [][2]string, err error) {
|
|
||||||
var r []*dg.Role
|
|
||||||
r, err = d.bot.GuildRoles(d.guildID)
|
|
||||||
if err != nil {
|
|
||||||
d.app.err.Printf("Discord: Failed to get roles: %v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
for _, role := range r {
|
|
||||||
fmt.Println(d.username)
|
|
||||||
if role.Name != d.username && role.Name != "@everyone" {
|
|
||||||
roles = append(roles, [2]string{role.ID, role.Name})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// roles = make([][2]string, len(r))
|
|
||||||
// for i, role := range r {
|
|
||||||
// roles[i] = [2]string{role.ID, role.Name}
|
|
||||||
// }
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// ApplyRole applies the member role to the given user if set.
|
|
||||||
func (d *DiscordDaemon) ApplyRole(userID string) error {
|
|
||||||
if d.roleID == "" {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return d.bot.GuildMemberRoleAdd(d.guildID, userID, d.roleID)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewTempInvite creates an invite link, and returns the invite URL, as well as the URL for the server icon.
|
// NewTempInvite creates an invite link, and returns the invite URL, as well as the URL for the server icon.
|
||||||
func (d *DiscordDaemon) NewTempInvite(ageSeconds, maxUses int) (inviteURL, iconURL string) {
|
func (d *DiscordDaemon) NewTempInvite(ageSeconds, maxUses int) (inviteURL, iconURL string) {
|
||||||
var inv *dg.Invite
|
var inv *dg.Invite
|
||||||
|
@ -127,21 +127,21 @@
|
|||||||
{{ if or (.telegramEnabled) (or .discordEnabled .matrixEnabled) }}
|
{{ if or (.telegramEnabled) (or .discordEnabled .matrixEnabled) }}
|
||||||
<div id="contact-via" class="unfocused">
|
<div id="contact-via" class="unfocused">
|
||||||
<label class="row switch pb-4">
|
<label class="row switch pb-4">
|
||||||
<input type="radio" name="contact-via" value="email" class="mr-2"><span>Contact through Email</span>
|
<input type="radio" name="contact-via" value="email"><span>Contact through Email</span>
|
||||||
</label>
|
</label>
|
||||||
{{ if .telegramEnabled }}
|
{{ if .telegramEnabled }}
|
||||||
<label class="row switch pb-4">
|
<label class="row switch pb-4">
|
||||||
<input type="radio" name="contact-via" value="telegram" id="contact-via-telegram" class="mr-2"><span>Contact through Telegram</span>
|
<input type="radio" name="contact-via" value="telegram" id="contact-via-telegram"><span>Contact through Telegram</span>
|
||||||
</label>
|
</label>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ if .discordEnabled }}
|
{{ if .discordEnabled }}
|
||||||
<label class="row switch pb-4">
|
<label class="row switch pb-4">
|
||||||
<input type="radio" name="contact-via" value="discord" id="contact-via-discord" class="mr-2"><span>Contact through Discord</span>
|
<input type="radio" name="contact-via" value="discord" id="contact-via-discord"><span>Contact through Discord</span>
|
||||||
</label>
|
</label>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ if .matrixEnabled }}
|
{{ if .matrixEnabled }}
|
||||||
<label class="row switch pb-4">
|
<label class="row switch pb-4">
|
||||||
<input type="radio" name="contact-via" value="matrix" id="contact-via-matrix" class="mr-2"><span>Contact through Matrix</span>
|
<input type="radio" name="contact-via" value="matrix" id="contact-via-matrix"><span>Contact through Matrix</span>
|
||||||
</label>
|
</label>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
|
@ -23,8 +23,7 @@ type newUserDTO struct {
|
|||||||
DiscordContact bool `json:"discord_contact"` // Whether or not to use discord for notifications/pwrs
|
DiscordContact bool `json:"discord_contact"` // Whether or not to use discord for notifications/pwrs
|
||||||
MatrixPIN string `json:"matrix_pin" example:"A1-B2-3C"` // Matrix verification PIN (if used)
|
MatrixPIN string `json:"matrix_pin" example:"A1-B2-3C"` // Matrix verification PIN (if used)
|
||||||
MatrixContact bool `json:"matrix_contact"` // Whether or not to use matrix for notifications/pwrs
|
MatrixContact bool `json:"matrix_contact"` // Whether or not to use matrix for notifications/pwrs
|
||||||
CaptchaID string `json:"captcha_id"` // Captcha ID (if enabled)
|
Captcha string `json:"captcha"` // Captcha text (if enabled)
|
||||||
CaptchaText string `json:"captcha_text"` // Captcha text (if enabled)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type newUserResponse struct {
|
type newUserResponse struct {
|
||||||
|
@ -263,8 +263,7 @@ interface sendDTO {
|
|||||||
discord_contact?: boolean;
|
discord_contact?: boolean;
|
||||||
matrix_pin?: string;
|
matrix_pin?: string;
|
||||||
matrix_contact?: boolean;
|
matrix_contact?: boolean;
|
||||||
captcha_id?: string;
|
captcha?: string;
|
||||||
captcha_text?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let captchaVerified = false;
|
let captchaVerified = false;
|
||||||
@ -339,8 +338,7 @@ const create = (event: SubmitEvent) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (window.captcha) {
|
if (window.captcha) {
|
||||||
send.captcha_id = captchaID;
|
send.captcha = captchaInput.value;
|
||||||
send.captcha_text = captchaInput.value;
|
|
||||||
}
|
}
|
||||||
_post("/newUser", send, (req: XMLHttpRequest) => {
|
_post("/newUser", send, (req: XMLHttpRequest) => {
|
||||||
if (req.readyState == 4) {
|
if (req.readyState == 4) {
|
||||||
|
2
views.go
2
views.go
@ -323,12 +323,10 @@ func (app *appContext) GenCaptcha(gc *gin.Context) {
|
|||||||
func (app *appContext) verifyCaptcha(code, id, text string) bool {
|
func (app *appContext) verifyCaptcha(code, id, text string) bool {
|
||||||
inv, ok := app.storage.invites[code]
|
inv, ok := app.storage.invites[code]
|
||||||
if !ok || inv.Captchas == nil {
|
if !ok || inv.Captchas == nil {
|
||||||
app.debug.Printf("Couldn't find invite \"%s\"", code)
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
c, ok := inv.Captchas[id]
|
c, ok := inv.Captchas[id]
|
||||||
if !ok {
|
if !ok {
|
||||||
app.debug.Printf("Couldn't find Captcha \"%s\"", id)
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return strings.ToLower(c.Text) == strings.ToLower(text)
|
return strings.ToLower(c.Text) == strings.ToLower(text)
|
||||||
|
Loading…
Reference in New Issue
Block a user