Skip to content

Commit 1ed0c54

Browse files
committed
Small work here and there
1 parent edce871 commit 1ed0c54

File tree

9 files changed

+140
-30
lines changed

9 files changed

+140
-30
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*.dll
44
*.so
55
*.dylib
6+
*.db
67

78
# Test binary, build with `go test -c`
89
*.test

frontend/client/App.vue

+5
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,9 @@ html {
9696
}
9797
}
9898
}
99+
100+
.content-article {
101+
color: whitesmoke;
102+
background-color: #3f3d49;
103+
}
99104
</style>

frontend/client/components/layout/Navbar.vue

+17-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<a class="navbar-item signed-text" v-if="session">
2727
<span>Hi, {{ session.display_name }}</span>
2828
<div class="avatar">
29-
<svg width="35" height="35" data-jdenticon-value="session.display_name"></svg>
29+
<svg class="avatar-img" data-jdenticon-value="session.display_name"></svg>
3030
</div>
3131
</a>
3232
<a class="navbar-item" v-if="session">
@@ -183,6 +183,22 @@ export default {
183183
184184
.avatar {
185185
margin-left: 10px;
186+
width: 40px;
187+
height: 40px;
188+
overflow: hidden;
189+
border-radius: 50%;
190+
position: relative;
191+
border-color: whitesmoke;
192+
border-style: solid;
193+
}
194+
195+
.avatar-img {
196+
position: absolute;
197+
width: 50px;
198+
height: 50px;
199+
top: 50%;
200+
left: 50%;
201+
transform: translate(-50%, -50%);
186202
}
187203
188204
.signed-text {

frontend/client/store/modules/menu/pipelines.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default {
1111

1212
subroute: [
1313
{
14-
name: 'Create Pipelines',
14+
name: 'Create Pipeline',
1515
path: '/pipelines/create',
1616
component: lazyLoading('pipelines/create'),
1717
meta: {
+14-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
<template>
2-
<div class="content has-text-centered">
3-
<h1 class="is-title is-bold">Create pipelines...</h1>
2+
<div class="tile is-ancestor">
3+
<div class="tile is-vertical is-3">
4+
<div class="tile">
5+
<div class="tile is-parent is-vertical">
6+
<article class="tile is-child notification content-article">
7+
<p class="subtitle">From Git repository</p>
8+
<div class="content">
9+
10+
</div>
11+
</article>
12+
</div>
13+
</div>
14+
</div>
415
</div>
516
</template>
617

@@ -10,7 +21,5 @@ export default {
1021
</script>
1122

1223
<style lang="scss" scoped>
13-
.is-title {
14-
text-transform: capitalize;
15-
}
24+
1625
</style>

frontend/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "gaia",
33
"version": "0.1.1",
4-
"description": "Build powerful pipelines with pure Go",
4+
"description": "Build powerful pipelines with any language",
55
"repository": "michelvocks/gaia",
66
"homepage": "https://github.com/michelvocks/gaia",
77
"license": "Apache-2.0",

handlers/User.go

+12-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package handlers
22

33
import (
4-
"fmt"
4+
"log"
55
"time"
66

77
jwt "github.com/dgrijalva/jwt-go"
@@ -30,20 +30,20 @@ func UserLogin(ctx iris.Context) {
3030

3131
// Authenticate user
3232
user, err := storeService.UserAuth(u)
33-
if err != nil || user == nil {
33+
if err != nil {
34+
log.Printf("error during UserAuth: %s", err)
35+
ctx.StatusCode(iris.StatusInternalServerError)
36+
return
37+
}
38+
if user == nil {
3439
ctx.StatusCode(iris.StatusForbidden)
3540
ctx.WriteString("invalid username and/or password")
36-
fmt.Printf("Error: %s", err)
3741
return
3842
}
3943

40-
// Remove password from object.
41-
// It's not needed anymore.
42-
u.Password = ""
43-
4444
// Setup custom claims
4545
claims := jwtCustomClaims{
46-
u.Username,
46+
user.Username,
4747
jwt.StandardClaims{
4848
ExpiresAt: time.Now().Unix() + jwtExpiry,
4949
IssuedAt: time.Now().Unix(),
@@ -59,13 +59,12 @@ func UserLogin(ctx iris.Context) {
5959
tokenstring, err := token.SignedString(b)
6060
if err != nil {
6161
ctx.StatusCode(iris.StatusInternalServerError)
62-
ctx.WriteString("Error during signing jwt token!")
63-
fmt.Printf("Error signing jwt token: %s", err.Error())
62+
log.Printf("Error signing jwt token: %s", err)
6463
return
6564
}
66-
u.JwtExpiry = claims.ExpiresAt
67-
u.Tokenstring = tokenstring
65+
user.JwtExpiry = claims.ExpiresAt
66+
user.Tokenstring = tokenstring
6867

6968
// Return JWT token and display name
70-
ctx.JSON(u)
69+
ctx.JSON(user)
7170
}

store/store.go

+51-9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ var (
1414

1515
// Name of the bucket where we store information about pipelines
1616
pipelineBucket = []byte("Pipelines")
17+
18+
// Username and password of the first admin user
19+
adminUsername = "admin"
20+
adminPassword = "admin"
1721
)
1822

1923
// Store represents the access type for store
@@ -52,31 +56,50 @@ func (s *Store) UserUpdate(u *gaia.User) error {
5256
// given password is valid. Returns nil if password was
5357
// wrong or user not found.
5458
func (s *Store) UserAuth(u *gaia.User) (*gaia.User, error) {
59+
// Look up user
60+
user, err := s.UserGet(u.Username)
61+
62+
// Error occured and/or user not found
63+
if err != nil || user == nil {
64+
return nil, err
65+
}
66+
67+
// Check if password is valid
68+
if user.Password != u.Password {
69+
return nil, nil
70+
}
71+
72+
// We will use the user object later.
73+
// But we don't need the password anymore.
74+
user.Password = ""
75+
76+
// Return user
77+
return user, nil
78+
}
79+
80+
// UserGet looks up a user by given username.
81+
// Returns nil if user was not found.
82+
func (s *Store) UserGet(username string) (*gaia.User, error) {
5583
user := &gaia.User{}
5684
err := s.db.View(func(tx *bolt.Tx) error {
5785
// Get bucket
5886
b := tx.Bucket(userBucket)
5987

6088
// Lookup user
61-
userRaw := b.Get([]byte(u.Username))
89+
userRaw := b.Get([]byte(username))
6290

6391
// User found?
6492
if userRaw == nil {
6593
// Nope. That is not an error so just leave
94+
user = nil
6695
return nil
6796
}
6897

6998
// Unmarshal
7099
return json.Unmarshal(userRaw, user)
71100
})
72101

73-
// Check if password is valid
74-
if err != nil || u.Password != user.Password {
75-
return nil, err
76-
}
77-
78-
// Return outcome
79-
return user, nil
102+
return user, err
80103
}
81104

82105
// Init initalizes the connection to the database.
@@ -89,7 +112,7 @@ func (s *Store) Init(cfg *gaia.Config) error {
89112
}
90113
s.db = db
91114

92-
// Create bucket if not exists
115+
// Create bucket if not exists function
93116
var bucketName []byte
94117
c := func(tx *bolt.Tx) error {
95118
_, err := tx.CreateBucketIfNotExists(bucketName)
@@ -111,5 +134,24 @@ func (s *Store) Init(cfg *gaia.Config) error {
111134
return err
112135
}
113136

137+
// Make sure that the user "admin" does exist
138+
admin, err := s.UserGet(adminUsername)
139+
if err != nil {
140+
return err
141+
}
142+
143+
// Create admin user if we cannot find it
144+
if admin == nil {
145+
err = s.UserUpdate(&gaia.User{
146+
DisplayName: adminUsername,
147+
Username: adminUsername,
148+
Password: adminPassword,
149+
})
150+
151+
if err != nil {
152+
return err
153+
}
154+
}
155+
114156
return nil
115157
}

store/store_test.go

+38
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,44 @@ func TestInit(t *testing.T) {
3232
}
3333
}
3434

35+
func TestUserGet(t *testing.T) {
36+
err := store.Init(config)
37+
if err != nil {
38+
t.Fatal(err)
39+
}
40+
41+
u := &gaia.User{}
42+
u.Username = "testuser"
43+
u.Password = "12345!#+21+"
44+
u.DisplayName = "Test"
45+
err = store.UserUpdate(u)
46+
if err != nil {
47+
t.Fatal(err)
48+
}
49+
50+
user, err := store.UserGet("userdoesnotexist")
51+
if err != nil {
52+
t.Fatal(err)
53+
}
54+
if user != nil {
55+
t.Fatalf("user object is not nil. We expected nil!")
56+
}
57+
58+
user, err = store.UserGet(u.Username)
59+
if err != nil {
60+
t.Fatal(err)
61+
}
62+
if user == nil {
63+
t.Fatalf("Expected user %v. Got nil.", u.Username)
64+
}
65+
66+
// cleanup
67+
err = os.Remove("test.db")
68+
if err != nil {
69+
t.Fatal(err)
70+
}
71+
}
72+
3573
func TestUserUpdate(t *testing.T) {
3674
err := store.Init(config)
3775
if err != nil {

0 commit comments

Comments
 (0)