Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

avoid user registering twice and change admin color (#126)

Guilherme Oenning298d7a8957a5
diff --git a/app/handlers/signin.go b/app/handlers/signin.go
index e4493a60c..e918e7423 100644
--- a/app/handlers/signin.go
+++ b/app/handlers/signin.go
@@ -216,13 +216,18 @@ func CompleteSignInProfile() web.HandlerFunc {
return c.HandleValidation(result)
}
+ _, err := c.Services().Users.GetByEmail(c.Tenant().ID, input.Model.Email)
+ if err != app.ErrNotFound {
+ return c.Ok(web.Map{})
+ }
+
user := &models.User{
Name: input.Model.Name,
Email: input.Model.Email,
Tenant: c.Tenant(),
Role: models.RoleVisitor,
}
- err := c.Services().Users.Register(user)
+ err = c.Services().Users.Register(user)
if err != nil {
return c.Failure(err)
}
diff --git a/app/handlers/signin_test.go b/app/handlers/signin_test.go
index 04a7f4fb0..b6d053863 100644
--- a/app/handlers/signin_test.go
+++ b/app/handlers/signin_test.go
@@ -259,7 +259,22 @@ func TestCompleteSignInProfileHandler_UnknownKey(t *testing.T) {
Expect(code).To(Equal(http.StatusBadRequest))
}
-func TestCompleteSignInProfileHandler_CorrecKey(t *testing.T) {
+func TestCompleteSignInProfileHandler_ExistingUser_CorrectKey(t *testing.T) {
+ RegisterTestingT(t)
+
+ server, services := mock.NewServer()
+
+ services.Tenants.SaveVerificationKey(mock.JonSnow.Email, "1234567890")
+
+ code, _ := server.
+ OnTenant(mock.DemoTenant).
+ WithURL("http://demo.test.fider.io/signin/complete").
+ ExecutePost(handlers.CompleteSignInProfile(), `{ "name": "Hot Pie", "key": "1234567890" }`)
+
+ Expect(code).To(Equal(http.StatusOK))
+}
+
+func TestCompleteSignInProfileHandler_CorrectKey(t *testing.T) {
RegisterTestingT(t)
server, services := mock.NewServer()
diff --git a/app/storage/inmemory/user.go b/app/storage/inmemory/user.go
index bbeac2444..8d5937205 100644
--- a/app/storage/inmemory/user.go
+++ b/app/storage/inmemory/user.go
@@ -1,6 +1,8 @@
package inmemory
import (
+ "errors"
+
"github.com/getfider/fider/app"
"github.com/getfider/fider/app/models"
)
@@ -49,8 +51,12 @@ func (s *UserStorage) Register(user *models.User) error {
s.lastID = s.lastID + 1
user.ID = s.lastID
}
- s.users = append(s.users, user)
- return nil
+ _, err := s.GetByEmail(user.Tenant.ID, user.Email)
+ if err == app.ErrNotFound || user.Email == "" {
+ s.users = append(s.users, user)
+ return nil
+ }
+ return errors.New("User already registered")
}
// RegisterProvider adds given provider to userID
diff --git a/public/assets/styles/variables.scss b/public/assets/styles/variables.scss
index 2b1a036d0..94fda5ae8 100644
--- a/public/assets/styles/variables.scss
+++ b/public/assets/styles/variables.scss
@@ -1,5 +1,5 @@
$main-color: #0069ff; //#0c9
-$admin-color: #CC615C;
+$admin-color: #5a93a6;
$bg-color: #fff;
$menu-color: #f9f9f9;