Skip to content

Commit

Permalink
Merge pull request #10 from myrunes/dev
Browse files Browse the repository at this point in the history
release v1.5.0
  • Loading branch information
zekroTJA authored Dec 18, 2019
2 parents 874a6cd + 32f5fbf commit a2c80dd
Show file tree
Hide file tree
Showing 49 changed files with 3,173 additions and 810 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: CI

on:
push:
paths-ignore:
- '**.md'

jobs:

build_backend:
name: Build Back End
runs-on: ubuntu-latest
steps:

- name: Set up Go 1.13
uses: actions/setup-go@v1
with:
go-version: 1.13
id: go

- name: Check out code
uses: actions/checkout@v1

- name: Get dependencies
run: |
go get -v -t -d ./...
- name: Build Backend
run: |
go build -v ./cmd/server/*.go
build_frontend:
name: Build Front End
runs-on: ubuntu-latest
steps:

- name: Use Node.js 13.x
uses: actions/setup-node@v1
with:
node-version: 13.x

- name: Check out code
uses: actions/checkout@v1

- name: Get dependencies
working-directory: ./web
run: |
npm ci
- name: Build Front End Files
working-directory: ./web
run: |
npm run build
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ RUN cd ./web &&\


FROM debian:stretch-slim AS final
RUN apt-get update &&\
apt-get install -y ca-certificates &&\
update-ca-certificates
WORKDIR /app
COPY --from=build /app .

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<strong>Save your League of Legends rune pages without wasting money.</strong><br><br>
<img src="https://forthebadge.com/images/badges/made-with-go.svg" height="30" />&nbsp;
<img src="https://forthebadge.com/images/badges/made-with-vue.svg" height="30" />&nbsp;
<img src="https://forthebadge.com/images/badges/fuck-it-ship-it.svg" height="30" />&nbsp;
<a href="https://stackshare.io/myrunes/myrunes"><img src="https://img.shields.io/badge/tech-stack-blue?style=for-the-badge" height="30"/></a>&nbsp;
<a href="https://zekro.de/discord"><img src="https://img.shields.io/discord/307084334198816769.svg?logo=discord&style=for-the-badge" height="30"></a>
<br/><br/>
<a href="https://hub.docker.com/r/zekro/myrunes"><img alt="Docker Cloud Automated build" src="https://img.shields.io/docker/cloud/automated/zekro/myrunes.svg?color=cyan&logo=docker&logoColor=cyan&style=for-the-badge"></a>&nbsp;
<a href="https://travis-ci.org/myrunes/myrunes"><img alt="Travis (.org)" src="https://img.shields.io/travis/myrunes/myrunes.svg?logo=travis&style=for-the-badge"></a>&nbsp;
<a href="https://stackshare.io/myrunes/myrunes"><img src="https://img.shields.io/badge/tech-stack-blue?style=for-the-badge" height="30"/></a>
<a href="https://hub.docker.com/r/zekro/myrunes"><img src="https://img.shields.io/docker/cloud/automated/zekro/myrunes.svg?color=cyan&logo=docker&logoColor=cyan&style=for-the-badge" height="30"></a>&nbsp;
<a href="https://travis-ci.org/myrunes/myrunes"><img src="https://img.shields.io/travis/myrunes/myrunes.svg?logo=travis&style=for-the-badge" height="30"></a>&nbsp;
<a href="https://github.com/myrunes/myrunes/actions"><img src="https://img.shields.io/github/workflow/status/myrunes/myrunes/CI?label=Actions&logo=github&style=for-the-badge" height="30"/></a>&nbsp;
</div>

---
Expand Down
10 changes: 9 additions & 1 deletion cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/myrunes/myrunes/internal/config"
"github.com/myrunes/myrunes/internal/database"
"github.com/myrunes/myrunes/internal/logger"
"github.com/myrunes/myrunes/internal/mailserver"
"github.com/myrunes/myrunes/internal/webserver"
"github.com/myrunes/myrunes/pkg/lifecycletimer"
)
Expand Down Expand Up @@ -73,8 +74,15 @@ func main() {
db.Close()
}()

logger.Info("MAILSERVER :: initialization")
ms, err := mailserver.NewMailServer(cfg.MailServer, "noreply@myrunes.com", "myrunes")
if err != nil {
logger.Fatal("MAILSERVER :: failed connecting to mail account: %s", err.Error())
}
logger.Info("MAILSERVER :: started")

logger.Info("WEBSERVER :: initialization")
ws := webserver.NewWebServer(db, cfg.WebServer, *flagAssets)
ws := webserver.NewWebServer(db, ms, cfg.WebServer, *flagAssets)
go func() {
if err := ws.ListenAndServeBlocking(); err != nil {
logger.Fatal("WEBSERVER :: failed starting web server: %s", err.Error())
Expand Down
11 changes: 11 additions & 0 deletions cmd/testing/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

import (
"fmt"

"github.com/myrunes/myrunes/pkg/comparison"
)

func main() {
fmt.Println(comparison.Alphabetically("ac", "ab"))
}
8 changes: 8 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ go 1.13
require (
github.com/bwmarrin/snowflake v0.3.0
github.com/ghodss/yaml v1.0.0
github.com/go-ozzo/ozzo-routing v2.1.4+incompatible // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/golang/gddo v0.0.0-20190904175337-72a348e765d2 // indirect
github.com/golang/snappy v0.0.1 // indirect
github.com/google/go-cmp v0.3.1 // indirect
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7
github.com/qiangxue/fasthttp-routing v0.0.0-20160225050629-6ccdc2a18d87
github.com/stretchr/testify v1.4.0 // indirect
github.com/tidwall/pretty v1.0.0 // indirect
github.com/valyala/fasthttp v1.6.0
github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c // indirect
github.com/xdg/stringprep v1.0.0 // indirect
Expand All @@ -17,5 +22,8 @@ require (
go.mongodb.org/mongo-driver v1.1.3
golang.org/x/crypto v0.0.0-20191119213627-4f8c1d86b1ba
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e // indirect
golang.org/x/tools v0.0.0-20191213221258-04c2e8eff935 // indirect
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
gopkg.in/yaml.v2 v2.2.7 // indirect
)
28 changes: 28 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0=
github.com/bwmarrin/snowflake v0.3.0/go.mod h1:NdZxfVWX+oR6y2K0o6qAYv6gIOP9rjG0/E9WsDpxqwE=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-ozzo/ozzo-routing v2.1.4+incompatible h1:gQmNyAwMnBHr53Nma2gPTfVVc6i2BuAwCWPam2hIvKI=
github.com/go-ozzo/ozzo-routing v2.1.4+incompatible/go.mod h1:hvoxy5M9SJaY0viZvcCsODidtUm5CzRbYKEWuQpr+2A=
github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/golang/gddo v0.0.0-20190904175337-72a348e765d2 h1:xisWqjiKEff2B0KfFYGpCqc3M3zdTz+OHQHRc09FeYk=
github.com/golang/gddo v0.0.0-20190904175337-72a348e765d2/go.mod h1:xEhNfoBDX1hzLm2Nf80qUvZ2sVwoMZ8d6IE2SrsQfh4=
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/klauspost/compress v1.8.2 h1:Bx0qjetmNjdFXASH02NSAREKpiaDwkO1DRZ3dV2KCcs=
github.com/klauspost/compress v1.8.2/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/cpuid v1.2.1 h1:vJi+O/nMdFt0vqm8NZBI6wzALWdA2X+egi0ogNyrC/w=
github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7 h1:lDH9UUVJtmYCjyT0CI4q8xvlXPxeZ0gYCVvWbmPlp88=
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/qiangxue/fasthttp-routing v0.0.0-20160225050629-6ccdc2a18d87 h1:u7uCM+HS2caoEKSPtSFQvvUDXQtqZdu3MYtF+QEw7vA=
github.com/qiangxue/fasthttp-routing v0.0.0-20160225050629-6ccdc2a18d87/go.mod h1:zwr0xP4ZJxwCS/g2d+AUOUwfq/j2NC7a1rK3F0ZbVYM=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.6.0 h1:uWF8lgKmeaIewWVPwi4GRq2P6+R46IgYZdxWtM+GtEY=
Expand All @@ -30,16 +45,29 @@ github.com/zekroTJA/timedmap v0.0.0-20191029102728-85f9d45635d7/go.mod h1:ktlw5a
go.mongodb.org/mongo-driver v1.1.3 h1:++7u8r9adKhGR+I79NfEtYrk2ktjenErXM99PSufIoI=
go.mongodb.org/mongo-driver v1.1.3/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191119213627-4f8c1d86b1ba h1:9bFeDpN3gTqNanMVqNcoR/pJQuP5uroC3t1D7eXozTE=
golang.org/x/crypto v0.0.0-20191119213627-4f8c1d86b1ba/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20191213221258-04c2e8eff935 h1:kJQZhwFzSwJS2BxboKjdZzWczQOZx8VuH7Y8hhuGUtM=
golang.org/x/tools v0.0.0-20191213221258-04c2e8eff935/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc h1:2gGKlE2+asNV9m7xrywl36YYNnBG5ZQ0r/BOOxqPpmk=
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc/go.mod h1:m7x9LTH6d71AHyAX77c9yqWCCa3UKHcVEj9y7hAtKDk=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df h1:n7WqCuqOuCbNr617RXOY0AWRXxgwEyPp2z+p0+hgMuE=
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df/go.mod h1:LRQQ+SO6ZHR7tOkpBDuZnXENFzX8qRjMDMyPD6BRkCw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo=
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
12 changes: 9 additions & 3 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import (

"github.com/ghodss/yaml"
"github.com/myrunes/myrunes/internal/database"
"github.com/myrunes/myrunes/internal/mailserver"
"github.com/myrunes/myrunes/internal/webserver"
)

type Main struct {
MongoDB *database.MongoConfig `json:"mongodb"`
WebServer *webserver.Config `json:"webserver"`
MongoDB *database.MongoConfig `json:"mongodb"`
WebServer *webserver.Config `json:"webserver"`
MailServer *mailserver.Config `json:"mailserver"`
}

func Open(loc string) (*Main, error) {
Expand Down Expand Up @@ -41,11 +43,15 @@ func cretaeDefault(loc string) error {
DataDB: "lol-runes",
},
WebServer: &webserver.Config{
Addr: ":443",
Addr: ":443",
PublicAddr: "https://myrunes.com",
TLS: &webserver.TLSConfig{
Enabled: true,
},
},
MailServer: &mailserver.Config{
Port: 465,
},
}

data, err := yaml.Marshal(def)
Expand Down
9 changes: 9 additions & 0 deletions internal/database/mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func (m *MongoDB) GetUser(uid snowflake.ID, username string) (*objects.User, err

ok, err := m.get(m.collections.users, bson.M{"$or": bson.A{
bson.M{"username": username},
bson.M{"mailaddress": username},
bson.M{"uid": uid},
}}, user)

Expand Down Expand Up @@ -139,6 +140,14 @@ func (m *MongoDB) EditUser(user *objects.User, login bool) (bool, error) {
oldUser.PageOrder = user.PageOrder
}

if user.MailAddress != "" {
if user.MailAddress == "__RESET__" {
oldUser.MailAddress = ""
} else {
oldUser.MailAddress = user.MailAddress
}
}

return true, m.insertOrUpdate(m.collections.users,
bson.M{"uid": oldUser.UID}, oldUser)
}
Expand Down
61 changes: 61 additions & 0 deletions internal/mailserver/mailserver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package mailserver

import (
"gopkg.in/gomail.v2"
)

type Config struct {
Host string `json:"host"`
Port int `json:"port"`
Username string `json:"username"`
Password string `json:"password"`
}

type MailServer struct {
dialer *gomail.Dialer

defFrom string
defFromName string
}

func NewMailServer(config *Config, defFrom, defFromName string) (*MailServer, error) {
ms := new(MailServer)
ms.dialer = gomail.NewPlainDialer(config.Host, config.Port, config.Username, config.Password)

closer, err := ms.dialer.Dial()
if err != nil {
return nil, err
}

defer closer.Close()

ms.defFrom = defFrom
ms.defFromName = defFromName

return ms, nil
}

func (ms *MailServer) SendMailRaw(msg *gomail.Message) error {
return ms.dialer.DialAndSend(msg)
}

func (ms *MailServer) SendMail(from, fromName, to, subject, body, bodyType string) error {
if from == "" {
from = ms.defFrom
}

if fromName == "" {
fromName = ms.defFromName
}

msg := gomail.NewMessage()
msg.SetAddressHeader("From", from, fromName)
msg.SetAddressHeader("To", to, "")
msg.SetHeader("Subject", subject)
msg.SetBody(bodyType, body)
return ms.SendMailRaw(msg)
}

func (ms *MailServer) SendMailFromDef(to, subject, body, bodyType string) error {
return ms.SendMail("", "", to, subject, body, bodyType)
}
2 changes: 1 addition & 1 deletion internal/objects/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func NewSharePage(ownerID, pageID snowflake.ID, maxAccesses int, expires time.Ti
AccessIPs: make([]string, 0),
}

share.Ident, err = random.GetRandBase64Str(5)
share.Ident, err = random.Base64(5)

return share, err
}
1 change: 1 addition & 0 deletions internal/objects/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var (
type User struct {
UID snowflake.ID `json:"uid"`
Username string `json:"username"`
MailAddress string `json:"mailaddress"`
DisplayName string `json:"displayname"`
PassHash []byte `json:"passhash,omitempty"`
LastLogin time.Time `json:"lastlogin"`
Expand Down
4 changes: 2 additions & 2 deletions internal/webserver/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"github.com/bwmarrin/snowflake"
"github.com/valyala/fasthttp"

routing "github.com/qiangxue/fasthttp-routing"
"github.com/myrunes/myrunes/internal/database"
"github.com/myrunes/myrunes/internal/objects"
"github.com/myrunes/myrunes/pkg/random"
routing "github.com/qiangxue/fasthttp-routing"
"golang.org/x/crypto/bcrypt"
)

Expand Down Expand Up @@ -62,7 +62,7 @@ func (auth *Authorization) CheckHash(hash, pass []byte) bool {
}

func (auth *Authorization) CreateSessionKey() (string, error) {
return random.GetRandBase64Str(sessionKeyLength)
return random.Base64(sessionKeyLength)
}

func (auth *Authorization) Login(ctx *routing.Context) bool {
Expand Down
Loading

0 comments on commit a2c80dd

Please sign in to comment.