Refactor to use aerogo/database

This commit is contained in:
2017-10-27 09:11:56 +02:00
parent c0d7b0d2df
commit b07a98ed32
18 changed files with 52 additions and 164 deletions

View File

@ -92,11 +92,7 @@ func InstallFacebookAuth(app *aero.Application) {
if user != nil {
// Add FacebookToUser reference
err = user.ConnectFacebook(fbUser.ID)
if err != nil {
ctx.Error(http.StatusInternalServerError, "Could not connect account to Facebook account", err)
}
user.ConnectFacebook(fbUser.ID)
// Save in DB
user.Save()
@ -110,7 +106,7 @@ func InstallFacebookAuth(app *aero.Application) {
var getErr error
// Try to find an existing user via the Facebook user ID
user, getErr = arn.GetUserFromTable("FacebookToUser", fbUser.ID)
user, getErr = arn.GetUserByFacebookID(fbUser.ID)
if getErr == nil && user != nil {
authLog.Info("User logged in via Facebook ID", user.ID, user.Nick, ctx.RealIP(), user.Email, user.RealName())
@ -148,18 +144,10 @@ func InstallFacebookAuth(app *aero.Application) {
user.Save()
// Register user
err = arn.RegisterUser(user)
if err != nil {
ctx.Error(http.StatusInternalServerError, "Could not register a new user", err)
}
arn.RegisterUser(user)
// Connect account to a Facebook account
err = user.ConnectFacebook(fbUser.ID)
if err != nil {
ctx.Error(http.StatusInternalServerError, "Could not connect account to Facebook account", err)
}
user.ConnectFacebook(fbUser.ID)
// Save user object again with updated data
user.Save()