Added frontpage and Google login

This commit is contained in:
Eduard Urbach 2017-06-15 23:03:55 +02:00
parent 938057a626
commit 2d8d8299ef
12 changed files with 99 additions and 33 deletions

BIN
images/login/facebook.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

BIN
images/login/google.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

BIN
images/login/twitter.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

13
layout/layout.go Normal file
View File

@ -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)
}

View File

@ -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

22
main.go
View File

@ -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

View File

@ -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

View File

@ -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,7 +14,10 @@ const maxPosts = 5
func Get(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user != nil {
if user == nil {
return frontpage.Get(ctx)
}
posts, err := arn.GetPosts()
if err != nil {
@ -27,7 +31,4 @@ func Get(ctx *aero.Context) string {
}
return ctx.HTML(components.Dashboard(posts))
}
return ctx.HTML("ARN 4.0 is currently under construction.<br><a href='https://paypal.me/blitzprog' target='_blank' rel='noopener'>Support the development</a><br><a href='/auth/google'>Login via Google</a>")
}

View File

@ -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())
}

View File

@ -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")

View File

@ -0,0 +1,11 @@
.login-buttons
horizontal-wrap
width 100%
justify-content center
.login-button
//
.login-button-image
max-width 236px
max-height 44px

View File

@ -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.")