Account stuff

This commit is contained in:
Torkel Ödegaard
2014-09-20 12:13:46 +02:00
parent cdabe50320
commit 40ff57d8c4
10 changed files with 42 additions and 24 deletions
+1 -1
View File
@@ -64,7 +64,7 @@ func (self *HttpServer) index(c *gin.Context) {
viewModel := &IndexDto{}
userAccount, _ := c.Get("userAccount")
if userAccount != nil {
viewModel.User.Login = userAccount.(*models.UserAccount).Login
viewModel.User.Login = userAccount.(*models.Account).Login
}
c.HTML(200, "index.html", viewModel)
+6 -2
View File
@@ -20,7 +20,7 @@ func (self *HttpServer) addCollaborator(c *gin.Context, auth *authContext) {
return
}
collaborator, err := self.store.GetUserAccountLogin(model.Email)
collaborator, err := self.store.GetAccountByLogin(model.Email)
if err != nil {
c.JSON(404, gin.H{"status": "Collaborator not found"})
return
@@ -39,7 +39,11 @@ func (self *HttpServer) addCollaborator(c *gin.Context, auth *authContext) {
return
}
self.store.SaveUserAccount(userAccount)
err = self.store.UpdateAccount(userAccount)
if err != nil {
c.JSON(500, gin.H{"status": err.Error()})
return
}
c.JSON(200, gin.H{"status": "Collaborator added"})
}
+2 -2
View File
@@ -6,8 +6,8 @@ import (
)
type authContext struct {
account *models.UserAccount
userAccount *models.UserAccount
account *models.Account
userAccount *models.Account
}
func (auth *authContext) getAccountId() int {
+1 -1
View File
@@ -24,7 +24,7 @@ func (self *HttpServer) loginPost(c *gin.Context) {
return
}
account, err := self.store.GetUserAccountLogin(loginModel.Email)
account, err := self.store.GetAccountByLogin(loginModel.Email)
if err != nil {
c.JSON(400, gin.H{"status": "some error"})
}
+2 -2
View File
@@ -27,14 +27,14 @@ func (self *HttpServer) registerUserPost(c *gin.Context) {
return
}
account := models.UserAccount{
account := models.Account{
UserName: registerModel.Email,
Login: registerModel.Email,
Email: registerModel.Email,
Password: registerModel.Password,
}
err := self.store.SaveUserAccount(&account)
err := self.store.CreateAccount(&account)
if err != nil {
log.Error("Failed to create user account, email: %v, error: %v", registerModel.Email, err)
c.JSON(500, gin.H{"status": "failed to create account"})
+2 -2
View File
@@ -13,8 +13,8 @@ var routeHandlers = make([]routeHandlerRegisterFn, 0)
func getRouteHandlerWrapper(handler routeHandlerFn) gin.HandlerFunc {
return func(c *gin.Context) {
authContext := authContext{
account: c.MustGet("usingAccount").(*models.UserAccount),
userAccount: c.MustGet("userAccount").(*models.UserAccount),
account: c.MustGet("usingAccount").(*models.Account),
userAccount: c.MustGet("userAccount").(*models.Account),
}
handler(c, &authContext)
}