mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
brush up email requirements
This commit is contained in:
parent
933fb9fcfd
commit
d3fc35989d
10 changed files with 149 additions and 10 deletions
47
app.rb
47
app.rb
|
@ -407,11 +407,46 @@ post '/create' do
|
|||
plan: params[:selected_plan]
|
||||
)
|
||||
@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
|
||||
|
||||
@site.save
|
||||
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
|
||||
redirect '/'
|
||||
else
|
||||
|
@ -1041,6 +1076,18 @@ post '/comment/:comment_id/delete' do |comment_id|
|
|||
return {result: 'error'}.to_json
|
||||
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|
|
||||
site = Site[username: username]
|
||||
|
||||
|
|
11
migrations/037_email_confirmation.rb
Normal file
11
migrations/037_email_confirmation.rb
Normal 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
|
|
@ -358,6 +358,10 @@ class Site < Sequel::Model
|
|||
super
|
||||
end
|
||||
|
||||
def before_create
|
||||
self.email_confirmation_token = SecureRandom.hex 3
|
||||
end
|
||||
|
||||
# def after_destroy
|
||||
# FileUtils.rm_rf file_path
|
||||
# super
|
||||
|
@ -379,6 +383,17 @@ class Site < Sequel::Model
|
|||
errors.add :username, 'User/site name cannot exceed 32 characters.'
|
||||
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
|
||||
user = self.class.select(:id, :username).filter(username: values[:username]).first
|
||||
|
||||
|
@ -522,7 +537,7 @@ class Site < Sequel::Model
|
|||
end
|
||||
|
||||
def host
|
||||
domain ? domain : "#{username}.neocities.org"
|
||||
!domain.empty? ? domain : "#{username}.neocities.org"
|
||||
end
|
||||
|
||||
def title
|
||||
|
|
|
@ -23,6 +23,7 @@ describe 'signup' do
|
|||
@site = Fabricate.attributes_for(:site)
|
||||
fill_in 'username', with: @site[:username]
|
||||
fill_in 'password', with: @site[:password]
|
||||
fill_in 'email', with: @site[:email]
|
||||
end
|
||||
|
||||
def visit_signup
|
||||
|
@ -137,6 +138,20 @@ describe 'signup' do
|
|||
site.tags.first.name.must_equal 'one'
|
||||
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
|
||||
fill_in_valid
|
||||
fill_in 'tags', with: ''
|
||||
|
@ -165,9 +180,14 @@ describe 'signin' do
|
|||
include Capybara::DSL
|
||||
|
||||
def fill_in_valid
|
||||
site = Fabricate.attributes_for :site
|
||||
fill_in 'username', with: site[:username]
|
||||
fill_in 'password', with: site[:password]
|
||||
@site = Fabricate.attributes_for :site
|
||||
fill_in 'username', with: @site[:username]
|
||||
fill_in 'password', with: @site[:password]
|
||||
end
|
||||
|
||||
def fill_in_valid_signup
|
||||
fill_in_valid
|
||||
fill_in 'email', with: @site[:email]
|
||||
end
|
||||
|
||||
before do
|
||||
|
@ -196,15 +216,13 @@ describe 'signin' do
|
|||
it 'logs in with proper credentials' do
|
||||
visit '/'
|
||||
click_button 'Create My Website'
|
||||
site = Fabricate.attributes_for(:site)
|
||||
fill_in 'username', with: site[:username]
|
||||
fill_in 'password', with: site[:password]
|
||||
fill_in_valid_signup
|
||||
click_button 'Create Home Page'
|
||||
Capybara.reset_sessions!
|
||||
visit '/'
|
||||
click_link 'Sign In'
|
||||
fill_in 'username', with: site[:username]
|
||||
fill_in 'password', with: site[:password]
|
||||
fill_in 'username', with: @site[:username]
|
||||
fill_in 'password', with: @site[:password]
|
||||
click_button 'Sign In'
|
||||
page.must_have_content 'Your Feed'
|
||||
end
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
Fabricator(:site) do
|
||||
username { SecureRandom.hex }
|
||||
password { 'abcde' }
|
||||
email { SecureRandom.uuid.gsub('-', '')+'@example.com' }
|
||||
end
|
|
@ -47,7 +47,7 @@
|
|||
<hr>
|
||||
|
||||
<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>
|
||||
<h5>Email</h5>
|
||||
<input class="input-Area" name="email" type="email" placeholder="youremail@example.com" value="<%= @site.email %>" style="width: 300px">
|
||||
|
|
12
views/site_email_confirmed.erb
Normal file
12
views/site_email_confirmed.erb
Normal 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>
|
9
views/site_email_not_confirmed.erb
Normal file
9
views/site_email_not_confirmed.erb
Normal 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>
|
11
views/templates/email_confirm.erb
Normal file
11
views/templates/email_confirm.erb
Normal 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
|
15
views/templates/email_welcome.erb
Normal file
15
views/templates/email_welcome.erb
Normal 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
|
Loading…
Add table
Reference in a new issue