Custom Frontend Login

This is a sample to add your custom frontend login for your theme (Be careful with theme folder name).

  1. Create a controller within your theme
    apps/themes/{theme_folder_name}/frontend_sessions_controller.rb
    class Themes::{ThemeFolderNameClass}::FrontendSessionsController < CamaleonCms::Apps::ThemesFrontController
    def login
    session[:return_to] = params[:redirect_to] if params[:redirect_to].present?
    render 'login'
    end

    def save_login
    if login_user_with_password(params[:username], params[:password])
    login_user(@user, false, (session[:return_to] || cama_root_path))
    session.delete(:return_to)
    else
    flash.now[:error] = 'Invalid access'
    login
    end
    end

    def logout
    params[:return_to] = cama_root_path
    cama_logout_user
    end
    end
  2. Create main routes
    apps/themes/{theme_folder_name}/config/routes_main.txt
    controller 'themes/{theme_folder_name}/frontend_sessions' do
    get :login
    post :save_login
    get :logout
    end
  3. Create the login view
    apps/themes/{theme_folder_name}/views/frontend_sessions/login.html.erb
    <%= render 'camaleon_cms/flash_messages' %>
    <%= form_tag url_for(action: :save_login) do %>
    <div class="form-group">
    <%= text_field_tag :username, params[:username], placeholder: 'Username', class: 'required' %>
    </div>
    <div class="form-group">
    <%= password_field_tag :password, nil, placeholder: 'Password', class: 'required' %>
    </div>
    <div class="form-group">
    <%= submit_tag 'Log In', class: 'btn' %>
    </div>
    <% end %>
  4. Restart server and navigate
    https:localhost:3000/login
    https:localhost:3000/logout
Created at: 26 Oct 20:17 | Updated at: 17 Sep 20:18