Giter Site home page Giter Site logo

samfundet / samfundetauth Goto Github PK

View Code? Open in Web Editor NEW
1.0 18.0 1.0 88 KB

A mountable Rails engine which provides an application with the basic methods for authentication against the member database of The student society of Trondheim.

License: MIT License

Ruby 100.00%

samfundetauth's Introduction

SamfundetAuth

This project rocks and uses MIT-LICENSE.

Installation

SamfundetAuth depens upon SamfundetDomain. However, neither of these gems has been published on eg. rubygems.org. Gem does not support fetching gems from Github repositories. This is a feature of the Bundler. This is why we need to specify both of the gems, as if one did not depend upon the other, even though it does.

Add the following lines to your Gemfile and run bundle install again.

# SamfundetDomain is a gem which provides the application with samfundets domain models.
gem 'samfundet_domain', :git => "git://github.com/Samfundet/SamfundetDomain.git"

# SamfundetAuth is a gem which provides the application with methods for authenticating against mdb2.
gem 'samfundet_auth', :git => "git://github.com/Samfundet/SamfundetAuth.git"

Copy the migrations to your project with the following commands.

rake samfundet_domain_engine:install:migrations
rake samfundet_auth:install:migrations

Run rake db:migrate to execute the newly created migrations.

You may add the following line to your db/seeds.rb to seed group types, groups, areas, member and roles. (samfundet_domain_engine:db:seed is automatically invoked from samfundet_auth.)

Rake::Task['samfundet_auth_engine:db:seed'].invoke

Updating

Run the following commands to update the gem.

bundle update --source samfundet_domain
bundle update --source samfundet_auth
rake samfundet_domain_engine:install:migrations
rake samfundet_auth:install:migrations

Run rake db:migrate again to execute any newly created migrations.

Usage

If installed correctly, you will have access to six new models: Group, GroupType, Area, Role, MembersRole and Member. They can all be utilized exactly like any other models. They may be decorated using standards ways of decorating models provided by engines.

Example

Below is some example code of how authentication can be done using samfundet_auth and declarative_authorization. The variable @current_user will then be available in your views.

class ApplicationController < ActionController::Base
  def current_user
    unless session[:member_id].nil?
      @current_user = Member.find session[:member_id]
    end
  end
end
class SessionsController < ApplicationController
  def new
  end

  def create
    member = Member.authenticate params[:member][:mail], params[:member][:passord]

    if member.nil?
      flash[:error] = "Du tastet inn feil brukernavn eller passord."
      redirect_to login_path
    else
      flash[:success] = "Du er nå logget inn."
      session[:member_id] = member.id
      redirect_to root_path
    end
  end
end
= semantic_form_for Member.new, :url => login_path do |f|
  = f.inputs do
    = f.input :mail
    = f.input :passord, :as => :password
  = f.actions do
    = f.action :submit, :label => "Logg inn"
YourApplication::Application.routes.draw do
  match '/login', :to => 'sessions#new', :via => :get
  match '/login', :to => 'sessions#create', :via => :post
end

samfundetauth's People

Contributors

eirikvaa avatar badeball avatar alfiehub avatar filip0 avatar cristeahub avatar tollefj avatar kiisol avatar aleksanb avatar evgiz avatar eivrei avatar simonra avatar molysgaard avatar stianste avatar konstahm avatar simonkv avatar ahammar avatar anderssorby avatar andereld avatar frenje123 avatar dependabot[bot] avatar

Stargazers

Rune Holmgren avatar

Watchers

Torstein avatar Håkon Sandsmark avatar Torstein Nicolaysen avatar Lorents Odin Gravås avatar  avatar James Cloos avatar  avatar Rune Holmgren avatar  avatar  avatar Glenn Aarøen avatar Katrine avatar  avatar Erlend Eriksen avatar  avatar  avatar Robin avatar  avatar

Forkers

molysgaard

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.