Commit 296cdd591f7f01ffdbe18cd6a839bbd0e624dfba
1 parent
b07e1b3a
Exists in
master
and in
4 other branches
Add optional signup.
Showing
14 changed files
with
125 additions
and
25 deletions
Show diff stats
app/assets/stylesheets/sections/login.scss
| ... | ... | @@ -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 | 10 | \ No newline at end of file | ... | ... |
app/models/user.rb
| ... | ... | @@ -35,7 +35,7 @@ |
| 35 | 35 | |
| 36 | 36 | class User < ActiveRecord::Base |
| 37 | 37 | devise :database_authenticatable, :token_authenticatable, :lockable, |
| 38 | - :recoverable, :rememberable, :trackable, :validatable, :omniauthable | |
| 38 | + :recoverable, :rememberable, :trackable, :validatable, :omniauthable, :registerable | |
| 39 | 39 | |
| 40 | 40 | attr_accessible :email, :password, :password_confirmation, :remember_me, :bio, :name, :username, |
| 41 | 41 | :skype, :linkedin, :twitter, :dark_scheme, :theme_id, :force_random_password, | ... | ... |
app/views/devise/passwords/new.html.erb
| ... | ... | @@ -5,5 +5,5 @@ |
| 5 | 5 | <br/> |
| 6 | 6 | <br/> |
| 7 | 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 | 9 | <% end %> | ... | ... |
app/views/devise/registrations/new.html.erb
| ... | ... | @@ -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" %> |
| ... | ... | @@ -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 | 13 | %br/ |
| 14 | 14 | = f.submit "Sign in", :class => "primary btn wide" |
| 15 | 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 | 23 | .clearfix |
| 18 | 24 | - if devise_mapping.omniauthable? && resource_class.omniauth_providers.present? |
| 19 | 25 | %div | ... | ... |
app/views/notify/new_user_email.html.haml
| ... | ... | @@ -6,7 +6,10 @@ |
| 6 | 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 | 7 | Hi #{@user['name']}! |
| 8 | 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 | 13 | %td{style: "font-size: 1px; line-height: 1px;", width: "21"} |
| 11 | 14 | %tr |
| 12 | 15 | %td{style: "font-size: 1px; line-height: 1px;", width: "21"} |
| ... | ... | @@ -15,8 +18,9 @@ |
| 15 | 18 | login.......................................... |
| 16 | 19 | %code= @user['email'] |
| 17 | 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 | 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 | 25 | = link_to "Click here to login", root_url |
| 22 | 26 | %td{style: "font-size: 1px; line-height: 1px;", width: "21"} | ... | ... |
config/gitlab.yml.example
config/initializers/1_settings.rb
| ... | ... | @@ -51,6 +51,7 @@ Settings.gitlab['protocol'] ||= Settings.gitlab.https ? "https" : "http" |
| 51 | 51 | Settings.gitlab['email_from'] ||= "gitlab@#{Settings.gitlab.host}" |
| 52 | 52 | Settings.gitlab['url'] ||= Settings.send(:build_gitlab_url) |
| 53 | 53 | Settings.gitlab['user'] ||= 'gitlab' |
| 54 | +Settings.gitlab['signup_enabled'] ||= false | |
| 54 | 55 | |
| 55 | 56 | Settings['gravatar'] ||= Settingslogic.new({}) |
| 56 | 57 | Settings.gravatar['enabled'] = true if Settings.gravatar['enabled'].nil? | ... | ... |
config/routes.rb
| ... | ... | @@ -121,7 +121,7 @@ Gitlab::Application.routes.draw do |
| 121 | 121 | |
| 122 | 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 | 127 | # Project Area | ... | ... |
spec/mailers/notify_spec.rb
| ... | ... | @@ -32,6 +32,7 @@ describe Notify do |
| 32 | 32 | end |
| 33 | 33 | |
| 34 | 34 | it 'contains the new user\'s password' do |
| 35 | + Gitlab.config.gitlab.stub(:signup_enabled).and_return(false) | |
| 35 | 36 | should have_body_text /#{new_user.password}/ |
| 36 | 37 | end |
| 37 | 38 | |
| ... | ... | @@ -40,6 +41,35 @@ describe Notify do |
| 40 | 41 | end |
| 41 | 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 | 73 | context 'for a project' do |
| 44 | 74 | describe 'items that are assignable, the email' do |
| 45 | 75 | let(:assignee) { create(:user, email: 'assignee@example.com') } | ... | ... |
spec/requests/admin/admin_users_spec.rb
| ... | ... | @@ -49,6 +49,7 @@ describe "Admin::Users" do |
| 49 | 49 | end |
| 50 | 50 | |
| 51 | 51 | it "should send valid email to user with email & password" do |
| 52 | + Gitlab.config.gitlab.stub(:signup_enabled).and_return(false) | |
| 52 | 53 | User.observers.enable :user_observer do |
| 53 | 54 | click_button "Save" |
| 54 | 55 | user = User.last |
| ... | ... | @@ -58,6 +59,18 @@ describe "Admin::Users" do |
| 58 | 59 | email.body.should have_content(@password) |
| 59 | 60 | end |
| 60 | 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 | 74 | end |
| 62 | 75 | |
| 63 | 76 | describe "GET /admin/users/:id" do | ... | ... |
spec/requests/api/users_spec.rb
| ... | ... | @@ -53,6 +53,36 @@ describe Gitlab::API do |
| 53 | 53 | end |
| 54 | 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 | 86 | describe "GET /user" do |
| 57 | 87 | it "should return current user" do |
| 58 | 88 | get api("/user", user) | ... | ... |