Add bump with ip

This commit is contained in:
Your Name 2020-06-04 16:02:46 -04:00
parent 7d96d46ac8
commit 1a31bb6b30
1 changed files with 92 additions and 97 deletions

25
main.go
View File

@ -2,19 +2,19 @@ package scsusers
import ( import (
"bytes" "bytes"
"crypto/rand"
"database/sql" "database/sql"
"encoding/base32"
"encoding/json"
"fmt" "fmt"
"github.com/jmoiron/sqlx"
"golang.org/x/crypto/bcrypt"
"html/template" "html/template"
"log" "log"
"crypto/rand"
"encoding/json"
"encoding/base32"
"net/smtp" "net/smtp"
"strings" "strings"
)
"github.com/jmoiron/sqlx"
"golang.org/x/crypto/bcrypt"
)
type templates struct { type templates struct {
Registration *template.Template Registration *template.Template
@ -182,9 +182,9 @@ func SaveUser(username string, d UserData) bool {
} }
func Bump(username string) { func Bump(username string, ip string) {
q:=fmt.Sprintf("update %s_auth set lastseen=CURRENT_TIMESTAMP where username ILIKE $1", c.TablePrefix) q := fmt.Sprintf("update %s_auth set lastseen=CURRENT_TIMESTAMP, set lastseenip=$2 where username ILIKE $1", c.TablePrefix)
_, err :=c.db.Exec(q, username) _, err := c.db.Exec(q, username, ip)
if err != nil { if err != nil {
log.Printf("scsusers.Bump: Error on user bump: %s : %s\n", username, err.Error()) log.Printf("scsusers.Bump: Error on user bump: %s : %s\n", username, err.Error())
} }
@ -195,7 +195,7 @@ type Metadata struct {
MetaValue string `db:meta_value` MetaValue string `db:meta_value`
} }
func GetAllMeta(username string) (map[string]string) { func GetAllMeta(username string) map[string]string {
meta := make(map[string]string) meta := make(map[string]string)
q := fmt.Sprintf(`select meta_key, meta_value q := fmt.Sprintf(`select meta_key, meta_value
from %s_user_metadata where from %s_user_metadata where
@ -253,7 +253,6 @@ func SetMeta(username string, metakey string, metavalue string) {
} }
} }
func RecoverByUsername(u string) { func RecoverByUsername(u string) {
var username, email string var username, email string
q := fmt.Sprintf("select username, email from %s_auth where username ILIKE $1", c.TablePrefix) q := fmt.Sprintf("select username, email from %s_auth where username ILIKE $1", c.TablePrefix)
@ -284,7 +283,6 @@ func RecoverByEmail(e string) {
} }
} }
func randBytes(n int) []byte { func randBytes(n int) []byte {
randomBytes := make([]byte, 32) randomBytes := make([]byte, 32)
_, err := rand.Read(randomBytes) _, err := rand.Read(randomBytes)
@ -321,7 +319,6 @@ func sendRegistrationEmail(recipient, username, password string) bool {
return true return true
} }
func sendAlertEmail(username, recipient, message string) bool { func sendAlertEmail(username, recipient, message string) bool {
data := struct { data := struct {
SiteName string SiteName string
@ -377,7 +374,6 @@ func sendRecoveryEmail(recipient, username, code string) bool {
return true return true
} }
func SetRegistrationTemplate(t string) bool { func SetRegistrationTemplate(t string) bool {
if len(t) != 0 { if len(t) != 0 {
r, err := template.New("reg").Parse(t) r, err := template.New("reg").Parse(t)
@ -414,7 +410,6 @@ func SetAlertTemplate(t string) bool {
return false return false
} }
func SetRecoveryTemplate(t string) bool { func SetRecoveryTemplate(t string) bool {
if len(t) != 0 { if len(t) != 0 {
r, err := template.New("recovery").Parse(t) r, err := template.New("recovery").Parse(t)