source: RedSur/app/controllers/registrations_controller.rb @ 101698b

modelo_minuta
Last change on this file since 101698b was 1b91e02, checked in by aosorio <aosorio@…>, 8 years ago

Version para desarrollo local

  • Property mode set to 100755
File size: 2.0 KB
Line 
1#   Copyright (c) 2010-2011, Diaspora Inc.  This file is
2#   licensed under the Affero General Public License version 3 or later.  See
3#   the COPYRIGHT file.
4
5class RegistrationsController < Devise::RegistrationsController
6  before_action :check_registrations_open_or_valid_invite!, :check_valid_invite!
7
8  layout ->(c) { request.format == :mobile ? "application" : "with_header" }, :only => [:new]
9
10  def create
11    @user = User.build(user_params)
12    @user.process_invite_acceptence(invite) if invite.present?
13
14    if @user.sign_up
15      flash[:notice] = I18n.t 'registrations.create.success'
16      #@user.seed_aspects
17      sign_in_and_redirect(:user, @user)
18      Rails.logger.info("event=registration status=successful user=#{@user.diaspora_handle}")
19    else
20      @user.errors.delete(:person)
21
22      flash[:error] = @user.errors.full_messages.join(" - ")
23      Rails.logger.info("event=registration status=failure errors='#{@user.errors.full_messages.join(', ')}'")
24      render :action => 'new', :layout => 'with_header'
25    end
26  end
27
28  def new
29    super
30  end
31
32  private
33
34  def check_valid_invite!
35    return true if AppConfig.settings.enable_registrations? #this sucks
36    return true if invite && invite.can_be_used?
37    flash[:error] = t('registrations.invalid_invite')
38    redirect_to new_user_session_path
39  end
40
41  def check_registrations_open_or_valid_invite!
42    return true if invite.present?
43    unless AppConfig.settings.enable_registrations?
44      flash[:error] = t('registrations.closed')
45      redirect_to new_user_session_path
46    end
47  end
48
49  def invite
50    if params[:invite].present?
51      @invite ||= InvitationCode.find_by_token(params[:invite][:token])
52    end
53  end
54
55  helper_method :invite
56
57  def user_params
58    params.require(:user).permit(:username, :email, :getting_started, :password, :password_confirmation, :language, :disable_mail, :invitation_service, :invitation_identifier, :show_community_spotlight_in_stream, :auto_follow_back, :auto_follow_back_aspect_id, :remember_me, :captcha, :captcha_key)
59  end
60end
Note: See TracBrowser for help on using the repository browser.