summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarin Jankovski <maxlazio@gmail.com>2012-11-06 14:30:48 +0100
committerMarin Jankovski <maxlazio@gmail.com>2013-01-18 11:57:31 +0100
commit296cdd591f7f01ffdbe18cd6a839bbd0e624dfba (patch)
treefd910106cf092da00a7fbddfe4d6e19b1f9a00eb
parentb07e1b3aedf87fdf3ec7a6855cec8194b0a30a59 (diff)
downloadgitlab-ce-296cdd591f7f01ffdbe18cd6a839bbd0e624dfba.tar.gz
Add optional signup.
-rw-r--r--app/assets/stylesheets/sections/login.scss5
-rw-r--r--app/controllers/registrations_controller.rb9
-rw-r--r--app/models/user.rb2
-rw-r--r--app/views/devise/passwords/new.html.erb2
-rw-r--r--app/views/devise/registrations/new.html.erb18
-rw-r--r--app/views/devise/registrations/new.html.haml19
-rw-r--r--app/views/devise/sessions/new.html.haml8
-rw-r--r--app/views/notify/new_user_email.html.haml10
-rw-r--r--config/gitlab.yml.example1
-rw-r--r--config/initializers/1_settings.rb1
-rw-r--r--config/routes.rb2
-rw-r--r--spec/mailers/notify_spec.rb30
-rw-r--r--spec/requests/admin/admin_users_spec.rb13
-rw-r--r--spec/requests/api/users_spec.rb30
14 files changed, 125 insertions, 25 deletions
diff --git a/app/assets/stylesheets/sections/login.scss b/app/assets/stylesheets/sections/login.scss
index 8c21de70013..7536abff44f 100644
--- a/app/assets/stylesheets/sections/login.scss
+++ b/app/assets/stylesheets/sections/login.scss
@@ -31,4 +31,9 @@ body.login-page{
margin-bottom: 20px;
}
+.login-box input.text.middle{
+ border-top: 0;
+ margin-bottom:0px;
+}
+
.login-box a.forgot{float: right; padding-top: 6px}
diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb
new file mode 100644
index 00000000000..cbac7613e59
--- /dev/null
+++ b/app/controllers/registrations_controller.rb
@@ -0,0 +1,9 @@
+class RegistrationsController < Devise::RegistrationsController
+ before_filter :signup_enabled?
+
+ private
+
+ def signup_enabled?
+ redirect_to new_user_session_path unless Gitlab.config.gitlab.signup_enabled
+ end
+end \ No newline at end of file
diff --git a/app/models/user.rb b/app/models/user.rb
index 55d75892fc4..7e69f3db84c 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -35,7 +35,7 @@
class User < ActiveRecord::Base
devise :database_authenticatable, :token_authenticatable, :lockable,
- :recoverable, :rememberable, :trackable, :validatable, :omniauthable
+ :recoverable, :rememberable, :trackable, :validatable, :omniauthable, :registerable
attr_accessible :email, :password, :password_confirmation, :remember_me, :bio, :name, :username,
:skype, :linkedin, :twitter, :dark_scheme, :theme_id, :force_random_password,
diff --git a/app/views/devise/passwords/new.html.erb b/app/views/devise/passwords/new.html.erb
index cf56c5d2710..860d67d19e7 100644
--- a/app/views/devise/passwords/new.html.erb
+++ b/app/views/devise/passwords/new.html.erb
@@ -5,5 +5,5 @@
<br/>
<br/>
<%= f.submit "Reset password", :class => "primary btn" %>
- <div class="right"> <%= render :partial => "devise/shared/links" %></div>
+ <div class="right"> <%= link_to "Sign in", new_session_path(resource_name), :class => "btn" %><br /></div>
<% end %>
diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb
deleted file mode 100644
index 4ac617c5912..00000000000
--- a/app/views/devise/registrations/new.html.erb
+++ /dev/null
@@ -1,18 +0,0 @@
-<h2>Sign up</h2>
-
-<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
- <%= devise_error_messages! %>
-
- <div><%= f.label :email %><br />
- <%= f.email_field :email %></div>
-
- <div><%= f.label :password %><br />
- <%= f.password_field :password %></div>
-
- <div><%= f.label :password_confirmation %><br />
- <%= f.password_field :password_confirmation %></div>
-
-<div><%= f.submit "Sign up", :class => "input_button" %></div>
-<% end %>
-
-<%= render :partial => "devise/shared/links" %>
diff --git a/app/views/devise/registrations/new.html.haml b/app/views/devise/registrations/new.html.haml
new file mode 100644
index 00000000000..81eb2622261
--- /dev/null
+++ b/app/views/devise/registrations/new.html.haml
@@ -0,0 +1,19 @@
+= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :class => "login-box" }) do |f|
+ = image_tag "login-logo.png", :width => "304", :height => "66", :class => "login-logo", :alt => "Login Logo"
+ = devise_error_messages!
+ %div
+ = f.text_field :name, :class => "text top", :placeholder => "Name", :required => true
+ %div
+ = f.text_field :username, :class => "text middle", :placeholder => "Username", :required => true
+ %div
+ = f.email_field :email, :class => "text middle", :placeholder => "Email", :required => true
+ %div
+ = f.password_field :password, :class => "text middle", :placeholder => "Password", :required => true
+ %div
+ = f.password_field :password_confirmation, :class => "text bottom", :placeholder => "Confirm password", :required => true
+ %div
+ = f.submit "Sign up", :class => "primary btn wide"
+ %br
+ %hr
+ = link_to "Sign in", new_session_path(resource_name)
+ = link_to "Forgot your password?", new_password_path(resource_name), :class => "right"
diff --git a/app/views/devise/sessions/new.html.haml b/app/views/devise/sessions/new.html.haml
index 474e7ef746c..0983f3157c4 100644
--- a/app/views/devise/sessions/new.html.haml
+++ b/app/views/devise/sessions/new.html.haml
@@ -13,7 +13,13 @@
%br/
= f.submit "Sign in", :class => "primary btn wide"
.right
- = render :partial => "devise/shared/links"
+ = link_to "Forgot your password?", new_password_path(resource_name), :class => "btn"
+ %br/
+ %br/
+ - if Gitlab.config.gitlab.signup_enabled
+ %hr/
+ Don't have an account?
+ = link_to "Sign up", new_registration_path(resource_name)
.clearfix
- if devise_mapping.omniauthable? && resource_class.omniauth_providers.present?
%div
diff --git a/app/views/notify/new_user_email.html.haml b/app/views/notify/new_user_email.html.haml
index 93bf7c50229..e8e9735587e 100644
--- a/app/views/notify/new_user_email.html.haml
+++ b/app/views/notify/new_user_email.html.haml
@@ -6,7 +6,10 @@
%h2{style: "color:#646464; font-weight: bold; margin: 0; padding: 0; line-height: 26px; font-size: 18px; font-family: Helvetica, Arial, sans-serif; "}
Hi #{@user['name']}!
%p{style: "color:#767676; font-weight: normal; margin: 0; padding: 0; line-height: 20px; font-size: 12px;font-family: Helvetica, Arial, sans-serif; "}
- Administrator created account for you. Now you are a member of company GitLab application.
+ - if Gitlab.config.gitlab.signup_enabled
+ Account has been created successfully.
+ - else
+ Administrator created account for you. Now you are a member of company GitLab application.
%td{style: "font-size: 1px; line-height: 1px;", width: "21"}
%tr
%td{style: "font-size: 1px; line-height: 1px;", width: "21"}
@@ -15,8 +18,9 @@
login..........................................
%code= @user['email']
%p{style: "color:#767676; font-weight: normal; margin: 0; padding: 0; line-height: 28px; font-size: 16px;font-family: Helvetica, Arial, sans-serif; "}
- password..................................
- %code= @password
+ - unless Gitlab.config.gitlab.signup_enabled
+ password..................................
+ %code= @password
%p{style: "color:#767676; font-weight: normal; margin: 0; padding: 0; line-height: 28px; font-size: 12px;font-family: Helvetica, Arial, sans-serif; "}
= link_to "Click here to login", root_url
%td{style: "font-size: 1px; line-height: 1px;", width: "21"}
diff --git a/config/gitlab.yml.example b/config/gitlab.yml.example
index c1266daffc3..26bd0696946 100644
--- a/config/gitlab.yml.example
+++ b/config/gitlab.yml.example
@@ -31,6 +31,7 @@ gitlab:
## Project settings
default_projects_limit: 10
+ # signup_enabled: true # default: false - Account passwords are not sent via the email if signup is enabled.
## Gravatar
gravatar:
diff --git a/config/initializers/1_settings.rb b/config/initializers/1_settings.rb
index 87c2399e08c..4e31b65fab0 100644
--- a/config/initializers/1_settings.rb
+++ b/config/initializers/1_settings.rb
@@ -51,6 +51,7 @@ Settings.gitlab['protocol'] ||= Settings.gitlab.https ? "https" : "http"
Settings.gitlab['email_from'] ||= "gitlab@#{Settings.gitlab.host}"
Settings.gitlab['url'] ||= Settings.send(:build_gitlab_url)
Settings.gitlab['user'] ||= 'gitlab'
+Settings.gitlab['signup_enabled'] ||= false
Settings['gravatar'] ||= Settingslogic.new({})
Settings.gravatar['enabled'] = true if Settings.gravatar['enabled'].nil?
diff --git a/config/routes.rb b/config/routes.rb
index ee6dfe6d3e6..446817356e8 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -121,7 +121,7 @@ Gitlab::Application.routes.draw do
resources :projects, constraints: { id: /[^\/]+/ }, only: [:new, :create]
- devise_for :users, controllers: { omniauth_callbacks: :omniauth_callbacks }
+ devise_for :users, controllers: { omniauth_callbacks: :omniauth_callbacks, registrations: :registrations }
#
# Project Area
diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb
index 01e3c3f14c4..d947f0e2882 100644
--- a/spec/mailers/notify_spec.rb
+++ b/spec/mailers/notify_spec.rb
@@ -32,6 +32,7 @@ describe Notify do
end
it 'contains the new user\'s password' do
+ Gitlab.config.gitlab.stub(:signup_enabled).and_return(false)
should have_body_text /#{new_user.password}/
end
@@ -40,6 +41,35 @@ describe Notify do
end
end
+
+ describe 'for users that signed up, the email' do
+ let(:example_site_path) { root_path }
+ let(:new_user) { create(:user, email: 'newguy@example.com', password: "securePassword") }
+
+ subject { Notify.new_user_email(new_user.id, new_user.password) }
+
+ it 'is sent to the new user' do
+ should deliver_to new_user.email
+ end
+
+ it 'has the correct subject' do
+ should have_subject /^gitlab \| Account was created for you$/i
+ end
+
+ it 'contains the new user\'s login name' do
+ should have_body_text /#{new_user.email}/
+ end
+
+ it 'should not contain the new user\'s password' do
+ Gitlab.config.gitlab.stub(:signup_enabled).and_return(true)
+ should_not have_body_text /#{new_user.password}/
+ end
+
+ it 'includes a link to the site' do
+ should have_body_text /#{example_site_path}/
+ end
+ end
+
context 'for a project' do
describe 'items that are assignable, the email' do
let(:assignee) { create(:user, email: 'assignee@example.com') }
diff --git a/spec/requests/admin/admin_users_spec.rb b/spec/requests/admin/admin_users_spec.rb
index a66e85a34f9..455caf4a376 100644
--- a/spec/requests/admin/admin_users_spec.rb
+++ b/spec/requests/admin/admin_users_spec.rb
@@ -49,6 +49,7 @@ describe "Admin::Users" do
end
it "should send valid email to user with email & password" do
+ Gitlab.config.gitlab.stub(:signup_enabled).and_return(false)
User.observers.enable :user_observer do
click_button "Save"
user = User.last
@@ -58,6 +59,18 @@ describe "Admin::Users" do
email.body.should have_content(@password)
end
end
+
+ it "should send valid email to user with email without password when signup is enabled" do
+ Gitlab.config.gitlab.stub(:signup_enabled).and_return(true)
+ User.observers.enable :user_observer do
+ click_button "Save"
+ user = User.last
+ email = ActionMailer::Base.deliveries.last
+ email.subject.should have_content("Account was created")
+ email.body.should have_content(user.email)
+ email.body.should_not have_content(@password)
+ end
+ end
end
describe "GET /admin/users/:id" do
diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb
index 4cfb4884e7c..ee5f510aac5 100644
--- a/spec/requests/api/users_spec.rb
+++ b/spec/requests/api/users_spec.rb
@@ -53,6 +53,36 @@ describe Gitlab::API do
end
end
+ describe "GET /users/sign_up" do
+ before do
+ Gitlab.config.gitlab.stub(:signup_enabled).and_return(false)
+ end
+ it "should redirect to sign in page if signup is disabled" do
+ get "/users/sign_up"
+ response.status.should == 302
+ response.should redirect_to(new_user_session_path)
+ end
+ end
+
+ describe "GET /users/sign_up" do
+ before do
+ Gitlab.config.gitlab.stub(:signup_enabled).and_return(true)
+ end
+ it "should return sign up page if signup is enabled" do
+ get "/users/sign_up"
+ response.status.should == 200
+ end
+ it "should create a new user account" do
+ visit new_user_registration_path
+ fill_in "user_name", with: "Name Surname"
+ fill_in "user_username", with: "Great"
+ fill_in "user_email", with: "name@mail.com"
+ fill_in "user_password", with: "password1234"
+ fill_in "user_password_confirmation", with: "password1234"
+ expect { click_button "Sign up" }.to change {User.count}.by(1)
+ end
+ end
+
describe "GET /user" do
it "should return current user" do
get api("/user", user)