Working on signup and signin

This commit is contained in:
Kyle Drake 2013-05-25 13:57:17 -07:00
parent 50882756d0
commit 4ddd244588
12 changed files with 105 additions and 11 deletions

1
.gitignore vendored
View file

@ -18,3 +18,4 @@ _yardoc
doc/ doc/
tests/coverage tests/coverage
config.yml config.yml
.DS_Store

View file

@ -82,6 +82,9 @@ DEPENDENCIES
fabrication fabrication
faker faker
hiredis hiredis
jdbc-postgres
jruby-openssl
json
minitest minitest
minitest-reporters minitest-reporters
mocha mocha
@ -92,6 +95,7 @@ DEPENDENCIES
rack-test rack-test
rake rake
redis redis
ruby-debug
sequel sequel
shotgun shotgun
simplecov simplecov

6
app.rb
View file

@ -13,6 +13,10 @@ get '/dashboard' do
slim :'dashboard' slim :'dashboard'
end end
get '/signin' do
slim :'signin'
end
post '/create' do post '/create' do
@site = Site.new username: params[:username], password: params[:password], email: params[:email] @site = Site.new username: params[:username], password: params[:password], email: params[:email]
if @site.valid? if @site.valid?
@ -39,7 +43,7 @@ post '/signin' do
redirect '/dashboard' redirect '/dashboard'
else else
flash[:error] = 'Invalid login.' flash[:error] = 'Invalid login.'
redirect '/' redirect '/signin'
end end
end end

View file

@ -0,0 +1,13 @@
Sequel.migration do
up {
DB.create_table! :tags do
primary_key :id
String :name
DateTime :created_at
end
}
down {
DB.drop_table :tags
}
end

View file

@ -0,0 +1,12 @@
Sequel.migration do
up {
DB.create_table! :site_tags do
Integer :site_id
Integer :tag_id
end
}
down {
DB.drop_table :site_tags
}
end

View file

@ -34,17 +34,17 @@ class Site < Sequel::Model
super super
if values[:username].nil? || values[:username].empty? if values[:username].nil? || values[:username].empty?
errors.add :username, 'valid username is required' errors.add :username, 'A valid username is required.'
end end
# Check for existing user # Check for existing user
user = self.class.select(:username).filter(username: values[:username]).first user = self.class.select(:username).filter(username: values[:username]).first
if !user.nil? && (user.id != values[:id]) if !user.nil? && (user.id != values[:id])
errors.add :username, 'this username is already taken' errors.add :username, 'This username is already taken. Try using another one.'
end end
if values[:password].nil? || (@password_length && @password_length < MINIMUM_PASSWORD_LENGTH) if values[:password].nil? || (@password_length && @password_length < MINIMUM_PASSWORD_LENGTH)
errors.add :password, "password must be at least #{MINIMUM_PASSWORD_LENGTH} characters" errors.add :password, "Password must be at least #{MINIMUM_PASSWORD_LENGTH} characters."
end end
end end
end end

View file

@ -0,0 +1,16 @@
::-webkit-input-placeholder { /* WebKit browsers */
color: #999;
}
:-moz-placeholder { /* Mozilla Firefox 4 to 18 */
color: #999;
}
::-moz-placeholder { /* Mozilla Firefox 19+ */
color: #999;
}
:-ms-input-placeholder { /* Internet Explorer 10+ */
color: #999;
}
textarea, input[type="text"], input[type="password"], input[type="datetime"], input[type="datetime-local"], input[type="date"], input[type="month"], input[type="time"], input[type="week"], input[type="number"], input[type="email"], input[type="url"], input[type="search"], input[type="tel"], input[type="color"], .uneditable-input {
color: #000000;
}

1
public/sites/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
*

View file

@ -3,7 +3,7 @@
h1 Your free home page is waiting.. once again. h1 Your free home page is waiting.. once again.
h2 NeoCities allows you to create your own free home page! h3 NeoCities allows you to create your own free home page.
div style="margin-top: 30px" div style="margin-top: 30px"
@ -26,4 +26,6 @@
td Hopefully with donations. If you feel this is a useful service, help us pay the bills to run it. <a href="/donate">Click here to contribute!</a> td Hopefully with donations. If you feel this is a useful service, help us pay the bills to run it. <a href="/donate">Click here to contribute!</a>
div.text-center div.text-center
h1: a href="/new" JOIN NOW h1: a href="/new" JOIN NOW
h5 style="margin-top: 30px" Returning users: <a href="/signin">Sign In</a>

View file

@ -17,6 +17,12 @@ html
.navbar .navbar
.navbar-inner .navbar-inner
a.brand href="/" NeoCities a.brand href="/" NeoCities
ul.nav.pull-right
- if signed_in?
li.navbar-text: strong style="color: #7AB800" #{session[:username]}
li: a href="/signout" style="color: #B94A48" Signout
- else
li: a href="/signin" <b>Sign in</b>
- flash.keys.each do |key| - flash.keys.each do |key|
div class="alert alert-#{key}" div class="alert alert-#{key}"

View file

@ -1,18 +1,26 @@
- if !@site.errors.empty?
.row
.span8.offset2
.alert.alert-block.alert-error
p Please correct the following errors:
- @site.errors.each do |error|
p = error.last.first
.row .row
.span8.offset3 .span8.offset3
form method="POST" action="/create" form method="POST" action="/create"
h2 Create a new Home Page h2 Create a new Home Page
.row .row
.span6 .span6
p First, enter a username. This will be used to login to your site. p First, enter a username. This will be used to login to your site.<br>It will also be the path of your web site.
.row .row
.span1 .span1
h5 Username h5 Username
.span6 .span6
input name="username" type="text" style="color: #000000" placeholder="bulbasaur1000" p http://neocities.org/<input name="username" type="text" placeholder="yourusername">
.row .row
.span6 .span6
@ -22,17 +30,30 @@
.span1 .span1
h5 Password h5 Password
.span6 .span6
input name="password" type="password" style="color: #000000" input name="password" type="password"
.row .row
.span6 .span6
p Now, you can enter an e-mail address if you want to be able to reset your password incase you lose it. This is optional, but recommended. <b>We will not give your email to anybody</b>. p Now you can enter an e-mail address. You don't have to provide one, but <b>we will not be able to reset your password without it, so don't lose your username and password if you leave this blank!</b>
.row .row
.span1 .span1
h5 Email h5 Email
.span6 .span6
input name="email" type="text" style="color: #000000" placeholder="youremail@example.com" input name="email" type="text" placeholder="youremail@example.com"
.row
.span6
p
| Enter some tags! Tags will allow others to find your site based on your interests, or your site's theme. <b>Separate multiple tags with commas</b>. Don't think too hard about this, you can change them later. You can have a maximum of ten tags, and there is a two word per tag maximum.
.row
.span1
h5 Tags
.span6
p: input name="tags" type="text" style="width: 400px" placeholder="pokemon, video games, bulbasaur"
.row style="margin-top: 30px" .row style="margin-top: 30px"
.span3.offset1 .span3.offset1
input.btn.btn-success.btn-large type="submit" value="Create Home Page" input.btn.btn-success.btn-large type="submit" value="Create Home Page"

14
views/signin.slim Normal file
View file

@ -0,0 +1,14 @@
.text-center
.row
.span12
h1 Welcome back!
.row
.span12
form method="POST" action="/signin"
fieldset
div: input name="username" type="text" placeholder="Your username"
div: input name="password" type="password" placeholder="Your password"
div: button class="btn btn-large btn-success" href="#" style="margin-top: 10px" Sign in
.row
.span12
a href="/new" I don't have an account yet.