brush up email requirements

This commit is contained in:
Kyle Drake 2014-08-02 15:22:54 -07:00
parent 933fb9fcfd
commit d3fc35989d
10 changed files with 149 additions and 10 deletions

47
app.rb
View file

@ -407,11 +407,46 @@ post '/create' do
plan: params[:selected_plan] plan: params[:selected_plan]
) )
@site.stripe_customer_id = customer.id @site.stripe_customer_id = customer.id
plan_name = customer.subscriptions.first['plan']['name']
EmailWorker.perform_async({
from: 'web@neocities.org',
reply_to: 'contact@neocities.org',
to: @site.email,
subject: "[Neocities] You've become a supporter!",
body: Tilt.new('./views/templates/email_subscription.erb', pretty: true).render(self, plan_name: plan_name)
})
end end
@site.save @site.save
end end
EmailWorker.perform_async({
from: 'web@neocities.org',
reply_to: 'contact@neocities.org',
to: @site.email,
subject: "[Neocities] Welcome to Neocities!",
body: Tilt.new('./views/templates/email_welcome.erb', pretty: true).render(self)
})
EmailWorker.perform_async({
from: 'web@neocities.org',
reply_to: 'contact@neocities.org',
to: @site.email,
subject: "[Neocities] Welcome to Neocities!",
body: Tilt.new('./views/templates/email_welcome.erb', pretty: true).render(self)
})
EmailWorker.perform_async({
from: 'web@neocities.org',
reply_to: 'contact@neocities.org',
to: @site.email,
subject: "[Neocities] Confirm your email address",
body: Tilt.new('./views/templates/email_confirm.erb', pretty: true).render(self)
})
session[:id] = @site.id session[:id] = @site.id
redirect '/' redirect '/'
else else
@ -1041,6 +1076,18 @@ post '/comment/:comment_id/delete' do |comment_id|
return {result: 'error'}.to_json return {result: 'error'}.to_json
end end
get '/site/:username/confirm_email/:token' do
site = Site[username: params[:username]]
if site.email_confirmation_token == params[:token]
site.email_confirmed = true
site.save
erb :'site_email_confirmed'
else
erb :'site_email_not_confirmed'
end
end
post '/site/:username/report' do |username| post '/site/:username/report' do |username|
site = Site[username: username] site = Site[username: username]

View file

@ -0,0 +1,11 @@
Sequel.migration do
up {
DB.add_column :sites, :email_confirmation_token, :text
DB.add_column :sites, :email_confirmed, :boolean, default: false
}
down {
DB.drop_column :sites, :email_confirmation_token
DB.drop_column :sites, :email_confirmed
}
end

View file

@ -358,6 +358,10 @@ class Site < Sequel::Model
super super
end end
def before_create
self.email_confirmation_token = SecureRandom.hex 3
end
# def after_destroy # def after_destroy
# FileUtils.rm_rf file_path # FileUtils.rm_rf file_path
# super # super
@ -379,6 +383,17 @@ class Site < Sequel::Model
errors.add :username, 'User/site name cannot exceed 32 characters.' errors.add :username, 'User/site name cannot exceed 32 characters.'
end end
# Check that email has been provided
if new? && values[:email].empty?
errors.add :email, 'An email address is required.'
end
# Check for existing email
if new? && self.class.select(:id).filter(email: values[:email]).first
errors.add :email, 'This email address already exists on Neocities, please use your existing account.'
end
# Check for existing user # Check for existing user
user = self.class.select(:id, :username).filter(username: values[:username]).first user = self.class.select(:id, :username).filter(username: values[:username]).first
@ -522,7 +537,7 @@ class Site < Sequel::Model
end end
def host def host
domain ? domain : "#{username}.neocities.org" !domain.empty? ? domain : "#{username}.neocities.org"
end end
def title def title

View file

@ -23,6 +23,7 @@ describe 'signup' do
@site = Fabricate.attributes_for(:site) @site = Fabricate.attributes_for(:site)
fill_in 'username', with: @site[:username] fill_in 'username', with: @site[:username]
fill_in 'password', with: @site[:password] fill_in 'password', with: @site[:password]
fill_in 'email', with: @site[:email]
end end
def visit_signup def visit_signup
@ -137,6 +138,20 @@ describe 'signup' do
site.tags.first.name.must_equal 'one' site.tags.first.name.must_equal 'one'
end end
it 'fails with existing email' do
email = Fabricate.attributes_for(:site)[:email]
fill_in_valid
fill_in 'email', with: email
click_button 'Create Home Page'
page.must_have_content 'Your Feed'
Capybara.reset_sessions!
visit_signup
fill_in_valid
fill_in 'email', with: email
click_button 'Create Home Page'
page.must_have_content /email.+exists/
end
it 'succeeds with no tags' do it 'succeeds with no tags' do
fill_in_valid fill_in_valid
fill_in 'tags', with: '' fill_in 'tags', with: ''
@ -165,9 +180,14 @@ describe 'signin' do
include Capybara::DSL include Capybara::DSL
def fill_in_valid def fill_in_valid
site = Fabricate.attributes_for :site @site = Fabricate.attributes_for :site
fill_in 'username', with: site[:username] fill_in 'username', with: @site[:username]
fill_in 'password', with: site[:password] fill_in 'password', with: @site[:password]
end
def fill_in_valid_signup
fill_in_valid
fill_in 'email', with: @site[:email]
end end
before do before do
@ -196,15 +216,13 @@ describe 'signin' do
it 'logs in with proper credentials' do it 'logs in with proper credentials' do
visit '/' visit '/'
click_button 'Create My Website' click_button 'Create My Website'
site = Fabricate.attributes_for(:site) fill_in_valid_signup
fill_in 'username', with: site[:username]
fill_in 'password', with: site[:password]
click_button 'Create Home Page' click_button 'Create Home Page'
Capybara.reset_sessions! Capybara.reset_sessions!
visit '/' visit '/'
click_link 'Sign In' click_link 'Sign In'
fill_in 'username', with: site[:username] fill_in 'username', with: @site[:username]
fill_in 'password', with: site[:password] fill_in 'password', with: @site[:password]
click_button 'Sign In' click_button 'Sign In'
page.must_have_content 'Your Feed' page.must_have_content 'Your Feed'
end end

View file

@ -1,4 +1,5 @@
Fabricator(:site) do Fabricator(:site) do
username { SecureRandom.hex } username { SecureRandom.hex }
password { 'abcde' } password { 'abcde' }
email { SecureRandom.uuid.gsub('-', '')+'@example.com' }
end end

View file

@ -47,7 +47,7 @@
<hr> <hr>
<p> <p>
Now you can enter an e-mail address. Your e-mail address is private and we will not show it to anyone for any reason. 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> Now you need to enter your e-mail address. Your e-mail address is private, we will not display it or give it to third-parties.
</p> </p>
<h5>Email</h5> <h5>Email</h5>
<input class="input-Area" name="email" type="email" placeholder="youremail@example.com" value="<%= @site.email %>" style="width: 300px"> <input class="input-Area" name="email" type="email" placeholder="youremail@example.com" value="<%= @site.email %>" style="width: 300px">

View file

@ -0,0 +1,12 @@
<div class="header-Outro">
<div class="row content single-Col">
<h1>Email Confirmed</h1>
</div>
</div>
<div class="content single-Col misc-page">
<h3>Your email address has been confirmed. Thank you!</h3>
<article>
<p><a href="/">Get Started</a></p>
</article>
</div>

View file

@ -0,0 +1,9 @@
<div class="header-Outro">
<div class="row content single-Col">
<h1>Email Not Confirmed</h1>
</div>
</div>
<div class="content single-Col misc-page">
<h3>The provided confirmation token was incorrect!</h3>
</div>

View file

@ -0,0 +1,11 @@
Hello <%= @site.username %>,
Please confirm your email address for Neocities!
You can confirm your email address using the link below:
https://neocities.org/site/<%= @site.username %>/confirm_email/<%= @site.email_confirmation_token %>
Thank you!
- The Neocities Team

View file

@ -0,0 +1,15 @@
Hello <%= @site.username %>, and welcome to Neocities!
Neocities is a community for people that make web sites, and you're now a member!
Making your first (or your latest) web site is a powerful thing. Unlike traditional social networks where you have no control over how your content is displayed, here you can create any kind of site you want, fill it with the content that matters to you, and share that site with everyone in the world. All you have to do is give out your web site address (<%= @site.host %>) for people to see your creation!
Since you're new, we've put together a basic "hello world" page for you. Now all you need to do is login and edit your "index.html" file, and you're on your way to being a webmaster of your own site on the World Wide Web!
If you have any questions or comments, or just want to say hi, feel free to contact us at https://neocities.org/contact. You can also reach us on Twitter at @neocitiesweb. We're super busy, so we can't help you with everything, but if you have a problem or bug to report, we'll try our best to look into it.
From Penelope (the Neocities' cat), the Neocities Team, and on behalf of all our sites, our very best wishes for you (and your awesome web site). We can't wait to see what it looks like!
Best,
- The Neocities Team