Main Avalanche Network server application. Built with Ruby on Rails.

registrations_controller.rb 2.7KB

    class Users::RegistrationsController < Devise::RegistrationsController # layout 'auth' def new # Check if open for signup @infos = Info.first if !@infos.open_for_signup @analytics.track('Access Denied') redirect_to root_path, notice: (t 'registration.not_open_for_signup', name: @infos.website_name) return end super end def create @user = User.where(email: params[:user][:email]).first if @user != nil if @user.invitation_accepted_at == nil && @user.invitation_sent_at != nil @user.destroy end end build_resource(sign_up_params) resource.save yield resource if block_given? if resource.persisted? @user = User.where(email: params[:user][:email]).first # Mixpanel Tracking Analytics @analytics.track_user_registration(@user) # Send signup email (worker) Resque.enqueue(SendSignupMessage, @user.id) if resource.active_for_authentication? set_flash_message :notice, :signed_up if is_flashing_format? sign_up(resource_name, resource) respond_with resource, location: after_sign_up_path_for(resource) else set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_flashing_format? expire_data_after_sign_in! respond_with resource, location: after_inactive_sign_up_path_for(resource) end else clean_up_passwords resource set_minimum_password_length respond_with resource end end def update @user = User.find(current_user.id) successfully_updated = if needs_password?(@user, params) @user.update_with_password(devise_parameter_sanitizer.sanitize(:account_update)) else # remove the virtual current_password attribute # update_without_password doesn't know how to ignore it params[:user].delete(:current_password) params[:user].delete(:password) params[:user].delete(:password_confirmation) @user.update_without_password(devise_parameter_sanitizer.sanitize(:account_update)) end if successfully_updated set_flash_message :notice, :updated @analytics.track('Profile updated') # Sign in the user bypassing validation in case his password changed sign_in @user, :bypass => true redirect_to edit_user_registration_path else render "edit" end end def after_sign_up_path_for(resource) dashboard_path end private # check if we need password to update user data # ie if password or email was changed # extend this as needed def needs_password?(user, params) user.email != params[:user][:email] || params[:user][:password].present? end end