Removed some leftover logs and updated the README
This commit is contained in:
+23
-8
@@ -1,20 +1,33 @@
|
|||||||
# WIP
|
# WIP
|
||||||
This is a simple webapp I use to track expenses. It has many holes and things
|
This is a simple webapp I use to track expenses. It has many holes and things
|
||||||
that don't work properly. I use this README internally to keep in mind what
|
that don't work properly, but the current feature set is:
|
||||||
I'm working on.
|
- Users (Authentication)
|
||||||
|
- Multiple APIs: Lua API, REST API that returns JSON and of course the core
|
||||||
|
`expenses` package itself that can be used separately
|
||||||
|
- Insert expenses via QR code (at least the data that is available, am working
|
||||||
|
on making the experience as seamless as possible)
|
||||||
|
- Share expenses arbitrarily with others
|
||||||
|
- Check the balance on your own expenses
|
||||||
|
|
||||||
|
|
||||||
|
There are many features to be implemented!
|
||||||
|
|
||||||
|
|
||||||
# BUGS
|
# BUGS
|
||||||
Inserting an expense where the owner has no payments results in a panic
|
- Inserting an expense where the owner has no payments results in a panic
|
||||||
|
|
||||||
|
|
||||||
# DOING
|
# DOING
|
||||||
- Auth
|
|
||||||
|
|
||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
- [ ] Users/Authentication/Autherization
|
- [X] Users/Authentication
|
||||||
- [ ] API
|
- [ ] Authorization
|
||||||
|
- [X] API (not complete, but going)
|
||||||
|
- [ ] Add more logging (and configure the logger)
|
||||||
|
- [ ] Need to add many UTs
|
||||||
|
- [ ] Need to think about where the authentication endpoints are its separation
|
||||||
|
of concerns
|
||||||
- [ ] Create an interface to get data from a QR code so that we can have both
|
- [ ] Create an interface to get data from a QR code so that we can have both
|
||||||
a web API and our go package
|
a web API and our go package
|
||||||
- [ ] If unable to connect to the database, try again, after X seconds
|
- [ ] If unable to connect to the database, try again, after X seconds
|
||||||
@@ -36,6 +49,7 @@ used
|
|||||||
- [X] Rename this file
|
- [X] Rename this file
|
||||||
- [ ] Better UX when adding expenses on the payments and share values (default even split)
|
- [ ] Better UX when adding expenses on the payments and share values (default even split)
|
||||||
- [ ] Verification popups for delete actions
|
- [ ] Verification popups for delete actions
|
||||||
|
- [ ] Allow user X to insert expense of user Y - make user Y have to approve it
|
||||||
|
|
||||||
|
|
||||||
### Stack
|
### Stack
|
||||||
@@ -59,5 +73,6 @@ used
|
|||||||
|
|
||||||
|
|
||||||
## Thanks to
|
## Thanks to
|
||||||
https://threedots.tech/post/database-transactions-in-go/
|
This excellent write up:
|
||||||
https://github.com/m110
|
- [Database Transactions in GO](https://threedots.tech/post/database-transactions-in-go/),
|
||||||
|
by [m110](https://github.com/m110)
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
exp "expenses/expenses"
|
exp "expenses/expenses"
|
||||||
"expenses/expenses/auth"
|
"expenses/expenses/auth"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -21,19 +20,14 @@ func login(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println("user:", loginData.Name)
|
|
||||||
log.Println("pass:", loginData.Pass)
|
|
||||||
|
|
||||||
user, err := exp.App.ValidateCredentials(loginData.Name, loginData.Pass)
|
user, err := exp.App.ValidateCredentials(loginData.Name, loginData.Pass)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Error validating user: ", err)
|
|
||||||
// TODO - go to an error page or login failed or something
|
// TODO - go to an error page or login failed or something
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
token, err := auth.GenerateToken(user.UserName)
|
token, err := auth.GenerateToken(user.UserName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Error generating token: ", err)
|
|
||||||
// TODO - get error return
|
// TODO - get error return
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,18 +14,14 @@ import (
|
|||||||
func AuthMiddleware() gin.HandlerFunc {
|
func AuthMiddleware() gin.HandlerFunc {
|
||||||
log.Println("Are we authing?")
|
log.Println("Are we authing?")
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
log.Println("Returning the auth middleware function")
|
|
||||||
var user *mod.User
|
var user *mod.User
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
// Check if we have a cookie for the session
|
// Check if we have a cookie for the session
|
||||||
session := sessions.Default(c)
|
session := sessions.Default(c)
|
||||||
uid := session.Get("user_id")
|
uid := session.Get("user_id")
|
||||||
log.Println("UID is: ", uid)
|
|
||||||
if uid != nil {
|
if uid != nil {
|
||||||
log.Println("Got UUID: ", uid)
|
|
||||||
user, err = exp.App.GetUser(uid.(int32))
|
user, err = exp.App.GetUser(uid.(int32))
|
||||||
log.Println("Got User: ", user)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO - what do we return here?
|
// TODO - what do we return here?
|
||||||
return
|
return
|
||||||
@@ -33,14 +29,12 @@ func AuthMiddleware() gin.HandlerFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if user == nil {
|
if user == nil {
|
||||||
log.Println("No User: ", user)
|
|
||||||
c.Redirect(http.StatusTemporaryRedirect, "/login")
|
c.Redirect(http.StatusTemporaryRedirect, "/login")
|
||||||
// Just to be sure I recon
|
// Just to be sure I recon
|
||||||
c.Abort()
|
c.Abort()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println("Setting User: ", user)
|
|
||||||
c.Set("user", user)
|
c.Set("user", user)
|
||||||
c.Next()
|
c.Next()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user