Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Lost password feature again

  • Loading branch information...
commit ddeb0995603bc713c7aaacd79b7d61c7f85a7180 1 parent 65ee7e1
@neirrek neirrek authored
View
2  Rakefile
@@ -1,4 +1,4 @@
-# require 'bundler/setup'
+require 'bundler/setup'
require 'rake'
require 'rake/testtask'
View
12 lib/httpcron.rb
@@ -1,3 +1,5 @@
+require 'bundler/setup'
+
require 'json'
require 'logger'
@@ -23,11 +25,11 @@ module HTTPCron
Mail.defaults do
delivery_method :smtp, {
- :address => HttpCronConfig.smtp_hostname,
- :port => HttpCronConfig.smtp_port,
- :domain => HttpCronConfig.smtp_domain,
- :user_name => HttpCronConfig.smtp_user,
- :password => HttpCronConfig.smtp_password,
+ :address => HTTPCron::Config.smtp_hostname,
+ :port => HTTPCron::Config.smtp_port,
+ :domain => HTTPCron::Config.smtp_domain,
+ :user_name => HTTPCron::Config.smtp_user,
+ :password => HTTPCron::Config.smtp_password,
:authentication => 'plain',
:enable_starttls_auto => true
}
View
9 lib/httpcron/actions/users.rb
@@ -50,11 +50,12 @@ class ApiServer < Sinatra::Base
post '/users' do
check_admin
- check_parameter_for_blank :username, :password
+ check_parameter_for_blank :username, :password, :email_address
user = User.new(:username => params[:username],
:admin => 'true' == params[:admin],
:timezone => (params[:timezone] || Config.server_timezone),
- :password => params[:password])
+ :password => params[:password],
+ :email_address => params[:email_address])
save_user user
end
@@ -129,9 +130,9 @@ def save_user(user)
def send_password(user)
user_name = user.username
user_password = user.password
- body = ERB.new(File.new('views/password_mail.erb').read).result(binding)
+ body = ERB.new(File.new('lib/httpcron/views/password_mail.erb').read).result(binding)
Mail.deliver do
- from HttpCronConfig.sender_email_address
+ from Config.sender_email_address
to user.email_address
subject 'Your httpcron password'
body body
View
2  lib/httpcron/config.rb
@@ -51,7 +51,7 @@ def self.smtp_password
end
def self.sender_email_address
- @@smtp_password ||= get_value('SENDER_EMAIL_ADDRESS', "noreply@#{HttpCronConfig.smtp_domain}")
+ @@smtp_password ||= get_value('SENDER_EMAIL_ADDRESS', "noreply@#{self.smtp_domain}")
end
private
View
6 lib/httpcron/models.rb
@@ -86,8 +86,8 @@ def before_validation
def validate
super
- validates_presence [:username, :timezone]
- validates_unique :username
+ validates_presence [:username, :timezone, :email_address]
+ validates_unique :username, :email_address
validate_timezone
validates_max_length 250, :username
validates_max_length MAX_TIMEZONE_LENGTH, :timezone
@@ -188,7 +188,7 @@ def validate
end
if User.count == 0
- User.create(:username => 'httpcronadmin', :admin => true, :password => 'httpcronadmin', :email_address => HttpCronConfig.admin_email_address)
+ User.create(:username => 'httpcronadmin', :admin => true, :password => 'httpcronadmin', :email_address => Config.admin_email_address)
end
end
View
6 test/admin_params_test.rb
@@ -12,7 +12,7 @@ def app
it 'uses limit' do
database.transaction do
- post '/users', 'username' => 'testuser', 'password' => 'testpassword'
+ post '/users', 'username' => 'testuser', 'password' => 'testpassword', 'email_address' => 'test@toto.com'
get '/users'
last_response.status.must_equal 200
@@ -49,7 +49,7 @@ def app
it 'uses order' do
database.transaction do
- post '/users', 'username' => 'testuser', 'password' => 'testpassword'
+ post '/users', 'username' => 'testuser', 'password' => 'testpassword', 'email_address' => 'test@toto.com'
get '/users', :order => 'id.desc'
last_response.status.must_equal 200
@@ -90,7 +90,7 @@ def app
it 'uses page' do
database.transaction do
- post '/users', 'username' => 'testuser', 'password' => 'testpassword'
+ post '/users', 'username' => 'testuser', 'password' => 'testpassword', 'email_address' => 'test@toto.com'
get '/users', :page => 0
last_response.status.must_equal 200
View
41 test/admin_user_test.rb
@@ -34,12 +34,17 @@ def app
it 'can send your password by email' do
database.transaction do
+ post '/users', 'username' => 'testuser', 'password' => 'testpassword', 'email_address' => 'test@toto.com'
Mail.defaults do
delivery_method :test
end
- get "/user/password/#{HttpCronConfig.admin_email_address}"
+ get "/user/password/test@toto.com"
Mail::TestMailer.deliveries.length.must_equal 1
- Mail::TestMailer.clear
+ Mail::TestMailer.deliveries.clear
+ get "/user/password/test@titi.com"
+ last_response.status.must_equal 404
+ last_response.body.must_equal 'No user found with email address [test@titi.com]'
+ raise(Sequel::Rollback)
end
end
@@ -58,7 +63,7 @@ def app
it 'can create user' do
database.transaction do
- post '/users', 'username' => 'testuser', 'password' => 'testpassword'
+ post '/users', 'username' => 'testuser', 'password' => 'testpassword', 'email_address' => 'test@toto.com'
last_response.status.must_equal 200
last_response.json_body['username'].must_equal 'testuser'
last_response.json_body['password'].must_equal nil
@@ -75,17 +80,22 @@ def app
it 'check for duplicates' do
database.transaction do
- post '/users', 'username' => 'testuser', 'password' => 'testpassword'
- post '/users', 'username' => 'testuser', 'password' => 'testpassword'
+ post '/users', 'username' => 'testuser', 'password' => 'testpassword', 'email_address' => 'test@toto.com'
+ post '/users', 'username' => 'testuser', 'password' => 'testpassword', 'email_address' => 'test2@toto.com'
last_response.status.must_equal 422
last_response.body.must_equal 'username is already taken'
+
+ post '/users', 'username' => 'testuser2', 'password' => 'testpassword', 'email_address' => 'test@toto.com'
+ last_response.status.must_equal 422
+ last_response.body.must_equal 'email_address is already taken'
+
raise(Sequel::Rollback)
end
end
it 'requires a username' do
database.transaction do
- post '/users', 'password' => 'testpassword'
+ post '/users', 'password' => 'testpassword', 'email_address' => 'test@toto.com'
last_response.status.must_equal 422
last_response.body.must_equal 'username is missing'
raise(Sequel::Rollback)
@@ -94,7 +104,7 @@ def app
it 'requires a not too long username' do
database.transaction do
- post '/users', 'username' => create_string(255), 'password' => 'testpassword'
+ post '/users', 'username' => create_string(255), 'password' => 'testpassword', 'email_address' => 'test@toto.com'
last_response.status.must_equal 422
last_response.body.must_equal 'username is longer than 250 characters'
raise(Sequel::Rollback)
@@ -103,16 +113,25 @@ def app
it 'requires a password' do
database.transaction do
- post '/users', 'username' => 'testuser'
+ post '/users', 'username' => 'testuser', 'email_address' => 'test@toto.com'
last_response.status.must_equal 422
last_response.body.must_equal 'password is missing'
raise(Sequel::Rollback)
end
end
- it 'can delete a user' do
+ it 'requires an email address' do
database.transaction do
post '/users', 'username' => 'testuser', 'password' => 'testpassword'
+ last_response.status.must_equal 422
+ last_response.body.must_equal 'email_address is missing'
+ raise(Sequel::Rollback)
+ end
+ end
+
+ it 'can delete a user' do
+ database.transaction do
+ post '/users', 'username' => 'testuser', 'password' => 'testpassword', 'email_address' => 'test@toto.com'
user_id = last_response_id
delete "/users/#{user_id}"
last_response.status.must_equal 200
@@ -135,7 +154,7 @@ def app
it 'can edit user' do
database.transaction do
- post '/users', 'username' => 'testuser', 'password' => 'testpassword'
+ post '/users', 'username' => 'testuser', 'password' => 'testpassword', 'email_address' => 'test@toto.com'
last_response.status.must_equal 200
user_id = last_response_id
@@ -150,7 +169,7 @@ def app
it 'requires a password when changing the username' do
database.transaction do
- post '/users', 'username' => 'testuser', 'password' => 'testpassword'
+ post '/users', 'username' => 'testuser', 'password' => 'testpassword', 'email_address' => 'test@toto.com'
last_response.status.must_equal 200
user_id = last_response_id
View
2  test/helper.rb
@@ -19,7 +19,7 @@ def json_body
# Create another user and authenticate with its identity
# return the user id
def create_non_admin_user_authenticate
- post '/users', 'username' => 'testuser', 'password' => 'testpassword'
+ post '/users', 'username' => 'testuser', 'password' => 'testpassword', 'email_address' => 'test@toto.com'
id_user = last_response.json_body['id']
digest_authorize 'testuser', 'testpassword'
id_user
Please sign in to comment.
Something went wrong with that request. Please try again.