Merge pull request #2050 from dosire/allow_self_signup
Add optional signup
This commit is contained in:
commit
c7c1a97c2f
14 changed files with 125 additions and 25 deletions
|
@ -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}
|
||||
|
|
9
app/controllers/registrations_controller.rb
Normal file
9
app/controllers/registrations_controller.rb
Normal file
|
@ -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
|
|
@ -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,
|
||||
|
|
|
@ -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 %>
|
||||
|
|
|
@ -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" %>
|
19
app/views/devise/registrations/new.html.haml
Normal file
19
app/views/devise/registrations/new.html.haml
Normal file
|
@ -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"
|
|
@ -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
|
||||
|
|
|
@ -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"}
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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') }
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue