Sha256: 8b52064a6d91bb1bec714e7ec795ef0bab841cd524aa78e2b868f8614f79f7d9

Contents?: true

Size: 1.29 KB

Versions: 6

Compression:

Stored size: 1.29 KB

Contents

require_dependency "fastui/application_controller"

module Fastui
  class SessionsController < ApplicationController
    respond_to :html, :xml, :json
    def login
      klass = params[:type] || 'Fastui::MPerson'
      user = klass.constantize.where(username: params[:username]).first

      respond_with(user) do |format|
        if UserAuthenticator.new(user).authenticate(params[:password])
          format.json { render :json => {:success => true, :msg => 'ok'} }
        else
          format.json { render :json => {:success => false, :msg => 'false'} }
        end
      end

      #if UserAuthenticator.new(user).authenticate(params[:password])
      #  #self.current_user = user
      #  redirect_to '/fastui'
      ##else
      #  flash[:alert] = "Login failed."
      #  render "new"
      #end

    end

    def logout

    end

    # assign them a random one and mail it to them, asking them to change it
    def forgot_password
      klass = params[:type] || 'Fastui::MPerson'
      @user = klass.constantize.where(username:params[:username])
      random_password = Array.new(10).map { (65 + rand(58)).chr }.join
      @user.password = random_password
      @user.save!
      #Mailer.create_and_deliver_password_change(@user, random_password)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
fastui-0.1.8 app/controllers/fastui/sessions_controller.rb
fastui-0.1.7 app/controllers/fastui/sessions_controller.rb
fastui-0.1.6 app/controllers/fastui/sessions_controller.rb
fastui-0.1.4 app/controllers/fastui/sessions_controller.rb
fastui-0.1.3 app/controllers/fastui/sessions_controller.rb
fastui-0.1.2 app/controllers/fastui/sessions_controller.rb