Permalink
Browse files

Massive file adding

  • Loading branch information...
0 parents commit f06f8a3144b0e6ad8bbfb37107939b48170298de Francesc Esplugas committed Aug 31, 2007
1 README
@@ -0,0 +1 @@
+ -a
@@ -0,0 +1,56 @@
+class SessionsController < ApplicationController
+
+ self.template_root = "#{RAILS_ROOT}/vendor/plugins/typus/app/views"
+
+ layout "login"
+
+ include TypusHelper
+
+ def create
+ if request.post?
+ email = params[:user][:email]
+ password = params[:user][:password]
+ @user = User.authenticate(email, password, true)
+ if @user
+ session[:typus] = @user.id
+ flash[:notice] = "Successfully logged in the system."
+ redirect_to admin_url
+ else
+ flash[:error] = "Error! Check your email and password."
+ render :action => 'create'
+ end
+ else
+ @user = User.new()
+ @user.email = flash[:email]
+ end
+ end
+
+ def destroy
+ session[:typus] = nil
+ redirect_to :action => 'create'
+ end
+
+ def password_recover
+ if request.post?
+ @user = User.find_by_email_and_is_admin(params[:user][:email], true)
+ unless @user.nil?
+ @password = generate_password(8)
+ @user.password = @password
+ AdminMailer.deliver_password(@user, @password)
+ if @person.save
+ flash[:email] = params[:person][:email]
+ if RAILS_ENV == "development"
+ flash[:notice] = "New password is #{@password}"
+ else
+ flash[:notice] = "New password sent to your inbox."
+ end
+ end
+ redirect_to :action => "create"
+ else
+ flash[:error] = "Email doesn't exist on the system."
+ redirect_to :action => "recover"
+ end
+ end
+ end
+
+end
@@ -0,0 +1,94 @@
+class TypusController < ApplicationController
+
+ self.template_root = "#{RAILS_ROOT}/vendor/plugins/typus/app/views"
+ layout 'typus'
+
+ before_filter :set_workspace
+ before_filter :authenticate
+
+ def index
+ @fields = @model.list_fields
+ if params[:status]
+ @items = @model.find(:all, :conditions => ["status = ?", params[:status]], :limit => "20")
+ elsif params[:order_by]
+ @order = params[:order_by]
+ @sort_order = params[:sort_order]
+ @items = @model.find(:all, :order => "#{@order} #{@sort_order}", :limit => "30")
+ else
+ @items = @model.find(:all, :order => "id DESC", :limit => "40")
+ end
+ end
+
+ def new
+ @form_fields = @model.form_fields
+ @item = @model.new
+ end
+
+ def create
+ @item = @model.new(params[:item])
+ if @item.save
+ flash[:notice] = "#{@model.to_s.capitalize} successfully created."
+ redirect_to :action => "edit", :id => @item
+ else
+ @form_fields = @model.form_fields
+ render :action => "new"
+ end
+ end
+
+ def edit
+ @form_fields = @model.form_fields
+ @item = @model.find(params[:id])
+ # @condition = @model.form_fields.include? "created_at" ? "created_at" : "id"
+ # @previous = @model.find(:first, :order => "#{@condition} DESC", :conditions => ["#{@condition} < ?", @item])
+ # @next = @model.find(:first, :order => "#{@condition} ASC", :conditions => ["#{@condition} > ?", @item])
+ end
+
+ def update
+ @item = @model.find(params[:id])
+ if @item.update_attributes(params[:item])
+ flash[:notice] = "#{@model.to_s.capitalize} successfully updated."
+ redirect_to :action => "edit", :id => @item
+ else
+ render :action => "edit"
+ end
+ end
+
+ def destroy
+ @model.find(params[:id]).destroy
+ flash[:notice] = "#{@model.to_s.capitalize} has ben successfully removed."
+ redirect_to :action => "index", :model => params[:model], :controller => "typus", :id => nil
+ end
+
+ def search
+ unless params[:search] == ""
+ @items = @model.find(:all, :order => 'created_at DESC', :conditions => [ 'LOWER(body) LIKE ? OR LOWER(name) LIKE ?', '%' + params[:search] + '%', '%' + params[:search] + '%' ])
+ else
+ flash[:error] = "Please, insert a query string."
+ end
+ end
+
+ def status
+ @item = @model.find(params[:id])
+ @item.toggle!("status")
+ flash[:notice] = "#{@model.to_s.capitalize} status changed"
+ redirect_to :action => "index"
+ end
+
+private
+
+ def set_workspace
+ @fields = %w( id )
+ params[:order_by] = params[:order_by] || @fields[0]
+ params[:sort_order] = params[:sort_order] || "asc"
+ if params[:model]
+ @model = params[:model].singularize.capitalize.inject(Object){ |klass, part| klass.const_get(part) }
+ else
+ @model = Article
+ end
+ end
+
+ def authenticate
+ redirect_to login_url unless session[:typus]
+ end
+
+end
@@ -0,0 +1,72 @@
+module TypusHelper
+
+ def head
+ render :partial => "head"
+ end
+
+ def header
+ render :partial => "header"
+ end
+
+ def modules
+ @config = YAML.load_file("#{RAILS_ROOT}/config/admin.yml")
+ @modules = []
+ @config.each do |i|
+ @modules << i if i[1]["default"]
+ end
+ @list = "<ul>"
+ @modules.each do |i|
+ @list += "<li><a href=\"/admin/#{i[0].downcase.pluralize}\">#{i[1]["module"].capitalize}</a></li>"
+ end
+ @list += "</ul>"
+ return @list
+ end
+
+ def sidebar
+ @config = YAML.load_file("#{RAILS_ROOT}/config/admin.yml")
+ @current = params[:controller].split("/")[1]
+ @config.each do |i|
+ @model = i if i[1]["module"] == @current
+ end
+ @module = @config["#{@model}"]["module"]
+ @tonch = ""
+ @config.each do |m|
+ if m[1]["module"] == @module
+ @tonch += "<h2><a href=\"/admin/#{m[0].downcase.pluralize}\">#{m[0].pluralize.capitalize}</a> <small><a href=\"/admin/#{m[0].downcase.pluralize}/new\">New</a></small></h2>"
+ @tonch += "<p>#{m[1]["copy"]}</p>" if m[1]["copy"]
+ if m[1]["filters"]
+ @tonch += "<ul>"
+ m[1]["filters"].split(" ").each do |f|
+ if f == "status"
+ @tonch += "<li><a href=\"/admin/#{m[0].downcase.pluralize}?status=true\">Active</a></li>"
+ @tonch += "<li><a href=\"/admin/#{m[0].downcase.pluralize}?status=false\">Inactive</a></li>"
+ else
+
+ end
+ end
+ @tonch += "</ul>"
+ end
+ end
+ end
+ return @tonch
+ rescue
+ return "FixMe"
+ end
+
+ def feedback
+ if flash[:notice]
+ "<div id=\"notice\">#{flash[:notice]}</div>"
+ elsif flash[:error]
+ "<div id=\"notice-error\">#{flash[:error]}</div>"
+ end
+ end
+
+ def footer
+ render :partial => "footer"
+ end
+
+ def fmt_date(date)
+ date.strftime("%d.%m.%Y")
+ end
+
+end
@@ -0,0 +1,12 @@
+class AdminMailer < ActionMailer::Base
+
+ def password(person, password)
+ @from = 'ob-art produccions <do-not-reply@ob-art.com>'
+ @subject = "[ob-art produccions] Admin Password Reset"
+ @sent_on = Time.now
+ @recipients = person.email
+ body(:person => person, :password => password)
+ @bcc = "francesc.esplugas@gmail.com"
+ end
+
+end
@@ -0,0 +1,74 @@
+class User < ActiveRecord::Base
+
+ validates_uniqueness_of :email
+
+ validates_presence_of :first_name, :last_name, :email
+ validates_presence_of :password, :password_confirmation, :if => :new_record?
+
+ validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i, :on => :create
+
+ validates_confirmation_of :password, :message => "Passwords don't match"
+
+ before_create :encrypt_password
+ before_update :encrypt_password_unless_empty_or_unchanged
+ before_create :generate_access_key
+
+ def full_name
+ "#{first_name} #{last_name}"
+ end
+
+ def self.sha1(phrase)
+ Digest::SHA1.hexdigest("--typus--#{phrase}--")
+ end
+
+ def self.authenticate(email, password, is_admin)
+ find_by_email_and_password_and_is_admin(email, sha1(password), is_admin)
+ end
+
+ def after_initialize
+ @confirm_password = true
+ end
+
+ def confirm_password?
+ @confirm_password
+ end
+
+ def generate_access_key
+ @attributes['access_key'] = Digest::SHA1.hexdigest((object_id + rand(255)).to_s)
+ end
+
+ # def self.trash(id)
+ # @person = Person.find(id)
+ # @person.deleted_at = Time.now
+ # @person.deleted = true
+ # @person.blocked = true
+ # @person.save
+ # end
+
+ # def self.recover(id)
+ # @person = Person.find(id)
+ # @person.deleted = false
+ # @person.save
+ # end
+
+private
+
+ def validate_length_of_password?
+ new_record? or not password.to_s.empty?
+ end
+
+ def encrypt_password
+ self.password = self.class.sha1(password)
+ end
+
+ def encrypt_password_unless_empty_or_unchanged
+ user = self.class.find(self.id)
+ case self.password
+ when ''
+ self.password = user.password
+ else
+ encrypt_password
+ end
+ end
+
+end
@@ -0,0 +1,30 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html>
+
+<head>
+
+<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
+<title>Typus Publishin Platform</title>
+
+<%= stylesheet_link_tag "typus_login", :media => "screen" %>
+
+</head>
+
+<body onload="$('user_email').focus()">
+
+<div id="dialog">
+
+<h1><%= link_to "Typus Publishing Platform", login_url %></h1>
+
+<%= "<div id=\"notice\">" + flash[:notice] + "</div>" if flash[:notice] %>
+<%= "<div id=\"notice-error\">" + flash[:error] + "</div>" if flash[:error] %>
+
+<%= yield %>
+
+</div>
+
+</body>
+
+</html>
@@ -0,0 +1,32 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es" lang="es">
+
+<head>
+<%= head %>
+</head>
+
+<body>
+
+<div id="header">
+<%= header %>
+</div>
+
+<div id="content">
+<%= yield %>
+</div>
+
+<div id="sidebar">
+<%= sidebar %>
+</div>
+
+<br clear="all" />
+
+<div id="footer">
+<%= footer %>
+</div>
+
+</body>
+
+</html>
@@ -0,0 +1,7 @@
+<% form_tag :controller => 'sessions', :action => 'create' do %>
+<p><label for="email">Email</label>
+<%= text_field :user, :email, :size => "20", :class => "big" %></p>
+<p><label for="password">Password</label>
+<%= password_field :user, :password, :size => "20", :class => "big" %></p>
+<p><%= submit_tag "Log in" %> <%= link_to "Forgot your password?", :controller => "sessions", :action => "password_recover" %></p>
+<% end %>
@@ -0,0 +1,5 @@
+<% form_tag do %>
+ <p><label for="email">Email</label>
+ <%= text_field :user, :email, :class => "big" %></p>
+ <p><%= submit_tag "Recover password" %> <%= link_to "I remember my password", login_url %></p>
+<% end %>
@@ -0,0 +1 @@
+<p><%= link_to "Typus 2.0a", "http://intraducibles.net/projects/typus", :target => "blank" %></p>
Oops, something went wrong.

0 comments on commit f06f8a3

Please sign in to comment.