Custom Frontend Login

This is a sample to add your custom frontend login for your theme.
Sample theme used: themes/default

  1. Create a controller within your theme
    apps/themes/default/frontend_sessions_controller.rb
    class Themes::Default::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/default/config/routes_main.txt
    controller 'themes/default/frontend_sessions' do
    get :login
    post :save_login
    get :logout
    end
  3. Create the login view
    apps/themes/default/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
    http:localhost:3001/login
    http:localhost:3001/logout