Commit 296cdd591f7f01ffdbe18cd6a839bbd0e624dfba

Authored by Marin Jankovski
1 parent b07e1b3a

Add optional signup.

app/assets/stylesheets/sections/login.scss
@@ -31,4 +31,9 @@ body.login-page{ @@ -31,4 +31,9 @@ body.login-page{
31 margin-bottom: 20px; 31 margin-bottom: 20px;
32 } 32 }
33 33
  34 +.login-box input.text.middle{
  35 + border-top: 0;
  36 + margin-bottom:0px;
  37 +}
  38 +
34 .login-box a.forgot{float: right; padding-top: 6px} 39 .login-box a.forgot{float: right; padding-top: 6px}
app/controllers/registrations_controller.rb 0 → 100644
@@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
  1 +class RegistrationsController < Devise::RegistrationsController
  2 + before_filter :signup_enabled?
  3 +
  4 + private
  5 +
  6 + def signup_enabled?
  7 + redirect_to new_user_session_path unless Gitlab.config.gitlab.signup_enabled
  8 + end
  9 +end
0 \ No newline at end of file 10 \ No newline at end of file
app/models/user.rb
@@ -35,7 +35,7 @@ @@ -35,7 +35,7 @@
35 35
36 class User < ActiveRecord::Base 36 class User < ActiveRecord::Base
37 devise :database_authenticatable, :token_authenticatable, :lockable, 37 devise :database_authenticatable, :token_authenticatable, :lockable,
38 - :recoverable, :rememberable, :trackable, :validatable, :omniauthable 38 + :recoverable, :rememberable, :trackable, :validatable, :omniauthable, :registerable
39 39
40 attr_accessible :email, :password, :password_confirmation, :remember_me, :bio, :name, :username, 40 attr_accessible :email, :password, :password_confirmation, :remember_me, :bio, :name, :username,
41 :skype, :linkedin, :twitter, :dark_scheme, :theme_id, :force_random_password, 41 :skype, :linkedin, :twitter, :dark_scheme, :theme_id, :force_random_password,
app/views/devise/passwords/new.html.erb
@@ -5,5 +5,5 @@ @@ -5,5 +5,5 @@
5 <br/> 5 <br/>
6 <br/> 6 <br/>
7 <%= f.submit "Reset password", :class => "primary btn" %> 7 <%= f.submit "Reset password", :class => "primary btn" %>
8 - <div class="right"> <%= render :partial => "devise/shared/links" %></div> 8 + <div class="right"> <%= link_to "Sign in", new_session_path(resource_name), :class => "btn" %><br /></div>
9 <% end %> 9 <% end %>
app/views/devise/registrations/new.html.erb
@@ -1,18 +0,0 @@ @@ -1,18 +0,0 @@
1 -<h2>Sign up</h2>  
2 -  
3 -<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>  
4 - <%= devise_error_messages! %>  
5 -  
6 - <div><%= f.label :email %><br />  
7 - <%= f.email_field :email %></div>  
8 -  
9 - <div><%= f.label :password %><br />  
10 - <%= f.password_field :password %></div>  
11 -  
12 - <div><%= f.label :password_confirmation %><br />  
13 - <%= f.password_field :password_confirmation %></div>  
14 -  
15 -<div><%= f.submit "Sign up", :class => "input_button" %></div>  
16 -<% end %>  
17 -  
18 -<%= render :partial => "devise/shared/links" %>  
app/views/devise/registrations/new.html.haml 0 → 100644
@@ -0,0 +1,19 @@ @@ -0,0 +1,19 @@
  1 += form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :class => "login-box" }) do |f|
  2 + = image_tag "login-logo.png", :width => "304", :height => "66", :class => "login-logo", :alt => "Login Logo"
  3 + = devise_error_messages!
  4 + %div
  5 + = f.text_field :name, :class => "text top", :placeholder => "Name", :required => true
  6 + %div
  7 + = f.text_field :username, :class => "text middle", :placeholder => "Username", :required => true
  8 + %div
  9 + = f.email_field :email, :class => "text middle", :placeholder => "Email", :required => true
  10 + %div
  11 + = f.password_field :password, :class => "text middle", :placeholder => "Password", :required => true
  12 + %div
  13 + = f.password_field :password_confirmation, :class => "text bottom", :placeholder => "Confirm password", :required => true
  14 + %div
  15 + = f.submit "Sign up", :class => "primary btn wide"
  16 + %br
  17 + %hr
  18 + = link_to "Sign in", new_session_path(resource_name)
  19 + = link_to "Forgot your password?", new_password_path(resource_name), :class => "right"
app/views/devise/sessions/new.html.haml
@@ -13,7 +13,13 @@ @@ -13,7 +13,13 @@
13 %br/ 13 %br/
14 = f.submit "Sign in", :class => "primary btn wide" 14 = f.submit "Sign in", :class => "primary btn wide"
15 .right 15 .right
16 - = render :partial => "devise/shared/links" 16 + = link_to "Forgot your password?", new_password_path(resource_name), :class => "btn"
  17 + %br/
  18 + %br/
  19 + - if Gitlab.config.gitlab.signup_enabled
  20 + %hr/
  21 + Don't have an account?
  22 + = link_to "Sign up", new_registration_path(resource_name)
17 .clearfix 23 .clearfix
18 - if devise_mapping.omniauthable? && resource_class.omniauth_providers.present? 24 - if devise_mapping.omniauthable? && resource_class.omniauth_providers.present?
19 %div 25 %div
app/views/notify/new_user_email.html.haml
@@ -6,7 +6,10 @@ @@ -6,7 +6,10 @@
6 %h2{style: "color:#646464; font-weight: bold; margin: 0; padding: 0; line-height: 26px; font-size: 18px; font-family: Helvetica, Arial, sans-serif; "} 6 %h2{style: "color:#646464; font-weight: bold; margin: 0; padding: 0; line-height: 26px; font-size: 18px; font-family: Helvetica, Arial, sans-serif; "}
7 Hi #{@user['name']}! 7 Hi #{@user['name']}!
8 %p{style: "color:#767676; font-weight: normal; margin: 0; padding: 0; line-height: 20px; font-size: 12px;font-family: Helvetica, Arial, sans-serif; "} 8 %p{style: "color:#767676; font-weight: normal; margin: 0; padding: 0; line-height: 20px; font-size: 12px;font-family: Helvetica, Arial, sans-serif; "}
9 - Administrator created account for you. Now you are a member of company GitLab application. 9 + - if Gitlab.config.gitlab.signup_enabled
  10 + Account has been created successfully.
  11 + - else
  12 + Administrator created account for you. Now you are a member of company GitLab application.
10 %td{style: "font-size: 1px; line-height: 1px;", width: "21"} 13 %td{style: "font-size: 1px; line-height: 1px;", width: "21"}
11 %tr 14 %tr
12 %td{style: "font-size: 1px; line-height: 1px;", width: "21"} 15 %td{style: "font-size: 1px; line-height: 1px;", width: "21"}
@@ -15,8 +18,9 @@ @@ -15,8 +18,9 @@
15 login.......................................... 18 login..........................................
16 %code= @user['email'] 19 %code= @user['email']
17 %p{style: "color:#767676; font-weight: normal; margin: 0; padding: 0; line-height: 28px; font-size: 16px;font-family: Helvetica, Arial, sans-serif; "} 20 %p{style: "color:#767676; font-weight: normal; margin: 0; padding: 0; line-height: 28px; font-size: 16px;font-family: Helvetica, Arial, sans-serif; "}
18 - password..................................  
19 - %code= @password 21 + - unless Gitlab.config.gitlab.signup_enabled
  22 + password..................................
  23 + %code= @password
20 %p{style: "color:#767676; font-weight: normal; margin: 0; padding: 0; line-height: 28px; font-size: 12px;font-family: Helvetica, Arial, sans-serif; "} 24 %p{style: "color:#767676; font-weight: normal; margin: 0; padding: 0; line-height: 28px; font-size: 12px;font-family: Helvetica, Arial, sans-serif; "}
21 = link_to "Click here to login", root_url 25 = link_to "Click here to login", root_url
22 %td{style: "font-size: 1px; line-height: 1px;", width: "21"} 26 %td{style: "font-size: 1px; line-height: 1px;", width: "21"}
config/gitlab.yml.example
@@ -31,6 +31,7 @@ gitlab: @@ -31,6 +31,7 @@ gitlab:
31 31
32 ## Project settings 32 ## Project settings
33 default_projects_limit: 10 33 default_projects_limit: 10
  34 + # signup_enabled: true # default: false - Account passwords are not sent via the email if signup is enabled.
34 35
35 ## Gravatar 36 ## Gravatar
36 gravatar: 37 gravatar:
config/initializers/1_settings.rb
@@ -51,6 +51,7 @@ Settings.gitlab[&#39;protocol&#39;] ||= Settings.gitlab.https ? &quot;https&quot; : &quot;http&quot; @@ -51,6 +51,7 @@ Settings.gitlab[&#39;protocol&#39;] ||= Settings.gitlab.https ? &quot;https&quot; : &quot;http&quot;
51 Settings.gitlab['email_from'] ||= "gitlab@#{Settings.gitlab.host}" 51 Settings.gitlab['email_from'] ||= "gitlab@#{Settings.gitlab.host}"
52 Settings.gitlab['url'] ||= Settings.send(:build_gitlab_url) 52 Settings.gitlab['url'] ||= Settings.send(:build_gitlab_url)
53 Settings.gitlab['user'] ||= 'gitlab' 53 Settings.gitlab['user'] ||= 'gitlab'
  54 +Settings.gitlab['signup_enabled'] ||= false
54 55
55 Settings['gravatar'] ||= Settingslogic.new({}) 56 Settings['gravatar'] ||= Settingslogic.new({})
56 Settings.gravatar['enabled'] = true if Settings.gravatar['enabled'].nil? 57 Settings.gravatar['enabled'] = true if Settings.gravatar['enabled'].nil?
config/routes.rb
@@ -121,7 +121,7 @@ Gitlab::Application.routes.draw do @@ -121,7 +121,7 @@ Gitlab::Application.routes.draw do
121 121
122 resources :projects, constraints: { id: /[^\/]+/ }, only: [:new, :create] 122 resources :projects, constraints: { id: /[^\/]+/ }, only: [:new, :create]
123 123
124 - devise_for :users, controllers: { omniauth_callbacks: :omniauth_callbacks } 124 + devise_for :users, controllers: { omniauth_callbacks: :omniauth_callbacks, registrations: :registrations }
125 125
126 # 126 #
127 # Project Area 127 # Project Area
spec/mailers/notify_spec.rb
@@ -32,6 +32,7 @@ describe Notify do @@ -32,6 +32,7 @@ describe Notify do
32 end 32 end
33 33
34 it 'contains the new user\'s password' do 34 it 'contains the new user\'s password' do
  35 + Gitlab.config.gitlab.stub(:signup_enabled).and_return(false)
35 should have_body_text /#{new_user.password}/ 36 should have_body_text /#{new_user.password}/
36 end 37 end
37 38
@@ -40,6 +41,35 @@ describe Notify do @@ -40,6 +41,35 @@ describe Notify do
40 end 41 end
41 end 42 end
42 43
  44 +
  45 + describe 'for users that signed up, the email' do
  46 + let(:example_site_path) { root_path }
  47 + let(:new_user) { create(:user, email: 'newguy@example.com', password: "securePassword") }
  48 +
  49 + subject { Notify.new_user_email(new_user.id, new_user.password) }
  50 +
  51 + it 'is sent to the new user' do
  52 + should deliver_to new_user.email
  53 + end
  54 +
  55 + it 'has the correct subject' do
  56 + should have_subject /^gitlab \| Account was created for you$/i
  57 + end
  58 +
  59 + it 'contains the new user\'s login name' do
  60 + should have_body_text /#{new_user.email}/
  61 + end
  62 +
  63 + it 'should not contain the new user\'s password' do
  64 + Gitlab.config.gitlab.stub(:signup_enabled).and_return(true)
  65 + should_not have_body_text /#{new_user.password}/
  66 + end
  67 +
  68 + it 'includes a link to the site' do
  69 + should have_body_text /#{example_site_path}/
  70 + end
  71 + end
  72 +
43 context 'for a project' do 73 context 'for a project' do
44 describe 'items that are assignable, the email' do 74 describe 'items that are assignable, the email' do
45 let(:assignee) { create(:user, email: 'assignee@example.com') } 75 let(:assignee) { create(:user, email: 'assignee@example.com') }
spec/requests/admin/admin_users_spec.rb
@@ -49,6 +49,7 @@ describe &quot;Admin::Users&quot; do @@ -49,6 +49,7 @@ describe &quot;Admin::Users&quot; do
49 end 49 end
50 50
51 it "should send valid email to user with email & password" do 51 it "should send valid email to user with email & password" do
  52 + Gitlab.config.gitlab.stub(:signup_enabled).and_return(false)
52 User.observers.enable :user_observer do 53 User.observers.enable :user_observer do
53 click_button "Save" 54 click_button "Save"
54 user = User.last 55 user = User.last
@@ -58,6 +59,18 @@ describe &quot;Admin::Users&quot; do @@ -58,6 +59,18 @@ describe &quot;Admin::Users&quot; do
58 email.body.should have_content(@password) 59 email.body.should have_content(@password)
59 end 60 end
60 end 61 end
  62 +
  63 + it "should send valid email to user with email without password when signup is enabled" do
  64 + Gitlab.config.gitlab.stub(:signup_enabled).and_return(true)
  65 + User.observers.enable :user_observer do
  66 + click_button "Save"
  67 + user = User.last
  68 + email = ActionMailer::Base.deliveries.last
  69 + email.subject.should have_content("Account was created")
  70 + email.body.should have_content(user.email)
  71 + email.body.should_not have_content(@password)
  72 + end
  73 + end
61 end 74 end
62 75
63 describe "GET /admin/users/:id" do 76 describe "GET /admin/users/:id" do
spec/requests/api/users_spec.rb
@@ -53,6 +53,36 @@ describe Gitlab::API do @@ -53,6 +53,36 @@ describe Gitlab::API do
53 end 53 end
54 end 54 end
55 55
  56 + describe "GET /users/sign_up" do
  57 + before do
  58 + Gitlab.config.gitlab.stub(:signup_enabled).and_return(false)
  59 + end
  60 + it "should redirect to sign in page if signup is disabled" do
  61 + get "/users/sign_up"
  62 + response.status.should == 302
  63 + response.should redirect_to(new_user_session_path)
  64 + end
  65 + end
  66 +
  67 + describe "GET /users/sign_up" do
  68 + before do
  69 + Gitlab.config.gitlab.stub(:signup_enabled).and_return(true)
  70 + end
  71 + it "should return sign up page if signup is enabled" do
  72 + get "/users/sign_up"
  73 + response.status.should == 200
  74 + end
  75 + it "should create a new user account" do
  76 + visit new_user_registration_path
  77 + fill_in "user_name", with: "Name Surname"
  78 + fill_in "user_username", with: "Great"
  79 + fill_in "user_email", with: "name@mail.com"
  80 + fill_in "user_password", with: "password1234"
  81 + fill_in "user_password_confirmation", with: "password1234"
  82 + expect { click_button "Sign up" }.to change {User.count}.by(1)
  83 + end
  84 + end
  85 +
56 describe "GET /user" do 86 describe "GET /user" do
57 it "should return current user" do 87 it "should return current user" do
58 get api("/user", user) 88 get api("/user", user)