diff --git a/images/login/facebook.png b/images/login/facebook.png new file mode 100644 index 00000000..d2997614 Binary files /dev/null and b/images/login/facebook.png differ diff --git a/images/login/google.png b/images/login/google.png new file mode 100644 index 00000000..02ee5f2c Binary files /dev/null and b/images/login/google.png differ diff --git a/images/login/twitter.png b/images/login/twitter.png new file mode 100644 index 00000000..83bb01a7 Binary files /dev/null and b/images/login/twitter.png differ diff --git a/layout/layout.go b/layout/layout.go new file mode 100644 index 00000000..9e617c67 --- /dev/null +++ b/layout/layout.go @@ -0,0 +1,13 @@ +package layout + +import ( + "github.com/aerogo/aero" + "github.com/animenotifier/notify.moe/components" + "github.com/animenotifier/notify.moe/utils" +) + +// Render layout. +func Render(ctx *aero.Context, content string) string { + user := utils.GetUser(ctx) + return components.Layout(ctx.App, user, content) +} diff --git a/layout/layout.pixy b/layout/layout.pixy index 7272cfae..95bbcc5f 100644 --- a/layout/layout.pixy +++ b/layout/layout.pixy @@ -1,4 +1,4 @@ -component Layout(app *aero.Application, content string) +component Layout(app *aero.Application, user *arn.User, content string) html(lang="en") head title= app.Config.Title @@ -7,7 +7,7 @@ component Layout(app *aero.Application, content string) body #container #header - Navigation + Navigation(user) #content-container main#content.fade!= content diff --git a/main.go b/main.go index cf84de8b..f92a2f74 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,7 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/arn" "github.com/animenotifier/notify.moe/components" + "github.com/animenotifier/notify.moe/layout" "github.com/animenotifier/notify.moe/pages/airing" "github.com/animenotifier/notify.moe/pages/anime" "github.com/animenotifier/notify.moe/pages/awards" @@ -34,9 +35,7 @@ func main() { app.Sessions.Store = arn.NewAerospikeStore("Session") // Layout - app.Layout = func(ctx *aero.Context, content string) string { - return components.Layout(app, content) - } + app.Layout = layout.Render // Production or Development mode host, _ := os.Hostname() @@ -64,11 +63,7 @@ func main() { // Favicon app.Get("/favicon.ico", func(ctx *aero.Context) string { - if ctx.CanUseWebP() { - return ctx.File("images/icons/favicon.webp") - } - - return ctx.File("images/icons/favicon.png") + return ctx.Image("images/icons/favicon", ".png") }) // Scripts @@ -83,13 +78,12 @@ func main() { // Cover image app.Get("/images/cover/:file", func(ctx *aero.Context) string { - format := ".jpg" + return ctx.Image("images/cover/"+ctx.Get("file"), ".jpg") + }) - if ctx.CanUseWebP() { - format = ".webp" - } - - return ctx.File("images/cover/" + ctx.Get("file") + format) + // Login buttons + app.Get("/images/login/:file", func(ctx *aero.Context) string { + return ctx.File("images/login/" + ctx.Get("file") + ".png") }) // Avatars diff --git a/mixins/Navigation.pixy b/mixins/Navigation.pixy index e9a48da9..75e1fd08 100644 --- a/mixins/Navigation.pixy +++ b/mixins/Navigation.pixy @@ -1,14 +1,34 @@ -component Navigation +component Navigation(user *arn.User) + if user == nil + LoggedOutMenu + else + LoggedInMenu + +component LoggedOutMenu nav#navigation NavigationButton("Dash", "/", "inbox") NavigationButton("Anime", "/anime", "television") NavigationButton("Forum", "/forum", "comment") NavigationButton("Users", "/users", "globe") NavigationButton("Airing", "/airing", "rss") - //- NavigationButton("Users", "/users", "globe") + +component LoggedInMenu + nav#navigation + NavigationButton("Dash", "/", "inbox") + NavigationButton("Anime", "/anime", "television") + NavigationButton("Forum", "/forum", "comment") + NavigationButton("Users", "/users", "globe") + NavigationButton("Airing", "/airing", "rss") + NavigationButtonNoAJAX("Logout", "/logout", "sign-out") component NavigationButton(name string, target string, icon string) a.navigation-link.ajax(href=target) + .navigation-button + i(class="fa fa-" + icon) + span.navigation-text= name + +component NavigationButtonNoAJAX(name string, target string, icon string) + a.navigation-link(href=target) .navigation-button i(class="fa fa-" + icon) span.navigation-text= name \ No newline at end of file diff --git a/pages/dashboard/dashboard.go b/pages/dashboard/dashboard.go index eb3914c7..af50fee9 100644 --- a/pages/dashboard/dashboard.go +++ b/pages/dashboard/dashboard.go @@ -4,6 +4,7 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/arn" "github.com/animenotifier/notify.moe/components" + "github.com/animenotifier/notify.moe/pages/frontpage" "github.com/animenotifier/notify.moe/utils" ) @@ -13,21 +14,21 @@ const maxPosts = 5 func Get(ctx *aero.Context) string { user := utils.GetUser(ctx) - if user != nil { - posts, err := arn.GetPosts() - - if err != nil { - return ctx.Error(500, "Error fetching posts", err) - } - - arn.SortPostsLatestFirst(posts) - - if len(posts) > maxPosts { - posts = posts[:maxPosts] - } - - return ctx.HTML(components.Dashboard(posts)) + if user == nil { + return frontpage.Get(ctx) } - return ctx.HTML("ARN 4.0 is currently under construction.
Support the development
Login via Google") + posts, err := arn.GetPosts() + + if err != nil { + return ctx.Error(500, "Error fetching posts", err) + } + + arn.SortPostsLatestFirst(posts) + + if len(posts) > maxPosts { + posts = posts[:maxPosts] + } + + return ctx.HTML(components.Dashboard(posts)) } diff --git a/pages/frontpage/frontpage.go b/pages/frontpage/frontpage.go new file mode 100644 index 00000000..94feb8fc --- /dev/null +++ b/pages/frontpage/frontpage.go @@ -0,0 +1,11 @@ +package frontpage + +import ( + "github.com/aerogo/aero" + "github.com/animenotifier/notify.moe/components" +) + +// Get ... +func Get(ctx *aero.Context) string { + return ctx.HTML(components.FrontPage()) +} diff --git a/pages/frontpage/frontpage.pixy b/pages/frontpage/frontpage.pixy new file mode 100644 index 00000000..7e7dbea9 --- /dev/null +++ b/pages/frontpage/frontpage.pixy @@ -0,0 +1,8 @@ +component FrontPage + p Anime Notifier 4.0 is currently under construction. + p + a(href="https://paypal.me/blitzprog", rel="noopener") Support the development + + .login-buttons + a.login-button(href="/auth/google") + img.login-button-image(src="/images/login/google", alt="Google Login", title="Login with your Google account") \ No newline at end of file diff --git a/pages/frontpage/frontpage.scarlet b/pages/frontpage/frontpage.scarlet new file mode 100644 index 00000000..2a43abf7 --- /dev/null +++ b/pages/frontpage/frontpage.scarlet @@ -0,0 +1,11 @@ +.login-buttons + horizontal-wrap + width 100% + justify-content center + +.login-button + // + +.login-button-image + max-width 236px + max-height 44px \ No newline at end of file diff --git a/patches/user-references/main.go b/patches/user-references/main.go index e9597a7d..4d3a591a 100644 --- a/patches/user-references/main.go +++ b/patches/user-references/main.go @@ -10,6 +10,7 @@ func main() { arn.DB.DeleteTable("NickToUser") arn.DB.DeleteTable("EmailToUser") + arn.DB.DeleteTable("GoogleToUser") // Get a stream of all anime allUsers, err := arn.AllUsers() @@ -29,6 +30,13 @@ func main() { if user.Email != "" { user.SetEmail(user.Email) } + + if user.Accounts.Google.ID != "" { + arn.DB.Set("GoogleToUser", user.Accounts.Google.ID, &arn.GoogleToUser{ + ID: user.Accounts.Google.ID, + UserID: user.ID, + }) + } } color.Green("Finished.")