From 57af3d2fb67cc14c15179b8f0ba46f7c13ef387d Mon Sep 17 00:00:00 2001 From: Xeronith Date: Tue, 25 Oct 2022 21:02:23 +0330 Subject: [PATCH] fix(app): :ambulance: resolve profile issue --- greataped/app/models/dto/auth.go | 18 +++++++++--------- greataped/app/routes/profile.go | 2 +- greataped/app/views/index.html | 27 ++++++++++++++++++++++++--- greataped/db/repos/auth.go | 8 +++----- 4 files changed, 37 insertions(+), 18 deletions(-) diff --git a/greataped/app/models/dto/auth.go b/greataped/app/models/dto/auth.go index 37c3bde..dbcabef 100644 --- a/greataped/app/models/dto/auth.go +++ b/greataped/app/models/dto/auth.go @@ -33,17 +33,17 @@ type VerifyResponse struct { type User struct { ID uint `json:"id"` Username string `json:"username"` - DisplayName string `json:"display_name,omitempty"` + DisplayName string `json:"display_name"` Email string `json:"email"` Password string `json:"-"` - Bio string `json:"bio,omitempty"` - Github string `json:"github,omitempty"` - Avatar string `json:"avatar,omitempty"` - Banner string `json:"banner,omitempty"` - ApiKey string `json:"api_key,omitempty"` - PublicKey string `json:"public_key,omitempty"` - Actor string `json:"actor,omitempty"` - Webfinger string `json:"webfinger,omitempty"` + Bio string `json:"bio"` + Github string `json:"github"` + Avatar string `json:"avatar"` + Banner string `json:"banner"` + ApiKey string `json:"api_key"` + PublicKey string `json:"public_key"` + Actor string `json:"actor"` + Webfinger string `json:"webfinger"` PrivateProfile bool `json:"private_profile"` } // @name User diff --git a/greataped/app/routes/profile.go b/greataped/app/routes/profile.go index 67bd0d1..19c42c6 100644 --- a/greataped/app/routes/profile.go +++ b/greataped/app/routes/profile.go @@ -66,7 +66,7 @@ var UpdateProfile = route.New(HttpPost, "/api/v1/profile", func(x IContext) erro } if err := repos.Default.UpdateProfile(user.ID, - Values{ + map[string]interface{}{ "display_name": body.DisplayName, "bio": body.Bio, "github": body.Github, diff --git a/greataped/app/views/index.html b/greataped/app/views/index.html index abff771..cb198f4 100644 --- a/greataped/app/views/index.html +++ b/greataped/app/views/index.html @@ -55,7 +55,12 @@
- +
@@ -123,8 +128,24 @@ }, }) .then(function (response) { - localStorage.setItem("token", response.data.auth.token); - window.location.href = "/profile"; + axios({ + method: "post", + url: "/api/v1/verify", + data: { + email: document.getElementById("email").value, + code: response.data.code, + }, + }) + .then(function (response) { + localStorage.setItem("token", response.data.auth.token); + window.location.href = "/profile"; + }) + .catch(function (err) { + document.getElementById("signupMessage").innerHTML = + err.response.data; + document.getElementById("signupMessage").style.display = + "block"; + }); }) .catch(function (err) { document.getElementById("signupMessage").innerHTML = diff --git a/greataped/db/repos/auth.go b/greataped/db/repos/auth.go index 9e83a0d..b5b73a5 100644 --- a/greataped/db/repos/auth.go +++ b/greataped/db/repos/auth.go @@ -8,11 +8,9 @@ import ( "gorm.io/gorm" ) -type Access int64 - const ( - ACCESS_PUBLIC Access = iota - ACCESS_PRIVATE + ACCESS_PUBLIC = 0 + ACCESS_PRIVATE = 1 ) // User struct defines the user @@ -29,7 +27,7 @@ type User struct { PublicKey string Avatar string Banner string - Access Access + Access int } // CreateUser create a user entry in the user's table