From f8aed9444aedfcb6f6b551b9d12a2491a04dc40c Mon Sep 17 00:00:00 2001 From: Hunter Long Date: Wed, 4 Jul 2018 18:50:01 -0700 Subject: [PATCH] force unique users - tmp changes --- .travis.yml | 1 + main_test.go | 14 ++++++++++++++ source/sql/mysql_up.sql | 5 +++-- source/sql/postgres_up.sql | 4 ++-- source/sql/sqlite_up.sql | 3 ++- source/tmpl/login.html | 7 +++---- 6 files changed, 25 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 67890916..3342cfce 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,6 +37,7 @@ before_deploy: deploy: - provider: releases api_key: $GH_TOKEN + if: branch = master file: - "build/statup-osx-x64.tar.gz" - "build/statup-osx-x32.tar.gz" diff --git a/main_test.go b/main_test.go index 959bcc0f..cc0739b1 100644 --- a/main_test.go +++ b/main_test.go @@ -64,6 +64,10 @@ func TestRunAll(t *testing.T) { t.Run(dbt+" Create Users", func(t *testing.T) { RunUser_Create(t) }) + t.Run(dbt+" Create Non Unique Users", func(t *testing.T) { + t.SkipNow() + RunUser_NonUniqueCreate(t) + }) t.Run(dbt+" Select Users", func(t *testing.T) { RunUser_SelectAll(t) }) @@ -275,6 +279,16 @@ func RunUser_Create(t *testing.T) { assert.Equal(t, int64(2), id) } +func RunUser_NonUniqueCreate(t *testing.T) { + user := &core.User{ + Username: "admin", + Password: "admin", + Email: "info@testuser.com", + } + _, err := user.Create() + assert.NotNil(t, err) +} + func RunUser_Delete(t *testing.T) { user, err := core.SelectUser(2) assert.Nil(t, err) diff --git a/source/sql/mysql_up.sql b/source/sql/mysql_up.sql index dd21ab07..7f5bdb79 100644 --- a/source/sql/mysql_up.sql +++ b/source/sql/mysql_up.sql @@ -13,12 +13,13 @@ CREATE TABLE users ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, username VARCHAR(50), password text, - email text, + email VARCHAR (50), api_key VARCHAR(50), api_secret VARCHAR(50), administrator BOOL NOT NULL DEFAULT '0', created_at DATETIME DEFAULT CURRENT_TIMESTAMP, - INDEX (id) + INDEX (id), + UNIQUE (username, email) ); CREATE TABLE services ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, diff --git a/source/sql/postgres_up.sql b/source/sql/postgres_up.sql index 006a4406..994dabd7 100644 --- a/source/sql/postgres_up.sql +++ b/source/sql/postgres_up.sql @@ -12,9 +12,9 @@ CREATE TABLE core ( CREATE TABLE users ( id SERIAL PRIMARY KEY, - username text, + username VARCHAR (50) UNIQUE, password text, - email text, + email VARCHAR (50) UNIQUE, api_key text, api_secret text, administrator bool, diff --git a/source/sql/sqlite_up.sql b/source/sql/sqlite_up.sql index 79791127..82104d73 100644 --- a/source/sql/sqlite_up.sql +++ b/source/sql/sqlite_up.sql @@ -18,7 +18,8 @@ CREATE TABLE users ( api_key text, api_secret text, administrator bool, - created_at DATETIME + created_at DATETIME, + UNIQUE (username, email) ); CREATE TABLE services ( diff --git a/source/tmpl/login.html b/source/tmpl/login.html index 2d3d493e..84db7e13 100644 --- a/source/tmpl/login.html +++ b/source/tmpl/login.html @@ -13,7 +13,7 @@
-
+
{{ if .Error }}
-
- - +
+