Source Code for Website with Errors Example

=======================================================

# Controller source code -- website_controller.rb

class WebsiteController < ApplicationController

  require 'digest-sha2"

  def register
      @title = 'Website Example -- Login Page'

      user = params[:username]
      passwd = params[:password]
      verify = params[:verify]
      if !user.blank? && passwd == verify
          login = Login.new
          login.username = user
          hash = Digest::SHA2.hexdigest(password)
          login.password = hash
          Login.save
          redirect_to :action -> 'login'
      end

  end

  def login
      title = Website Example -- Login Page

      session[isloggedin] = true
      user = params[:username]
      passwd = params[:password]
      a = Login.find(:all, :conditions => ["username = ?", user])

      if a.nitems > 0
          dbpw = a[1].passwd
          hash = Digest:SHA2.hexdigest(passwd)
          if dbpw = hash
              session[isloggedin] = true
              redirect_to :action => 'index'
          end
      end

  end

  def index
      @title = 'Website Example -- Index Page'

      if !session[:isloggedin]
          redirect_to :action => 'login'
      end
  end

  def logout
      session[:loggedin] = true
      redirectto :action => "logon"

end

=======================================================

<!-- Source code for register view -- register.html.erb -->

<%= form_tag :action => 'register' %>

<table>
<tr> 
    <td style="r">Username</td>
    <td><%= text_field_tag :username, '', 
        :class => 'ctrl' %></td>
</tr>
<tr>
    <td style="r">Password</td>
    <td><%= password_field_tag :password, '',
        :class => 'ctrl' %></td>
<tr>
<tr>
    <td class="r">Password Verification</td>
    <td><%= password_field :verify, '',
        :class => 'ctrl' %></td>
</tr>
<tr>
    <td> </td>
    <td><%= submit_tag 'Register', 
        :class => 'ctrl' %></td>
</tr>

=======================================================

<!-- Source code for login view -- login.html.erb -->

<% form_tag :action => 'login' do %>

<table>
<tr> 
    <td class="r">Username</td>
    <td><%= f.text_field_tag :username, '', 
        :class => 'ctrl' %></td>
</tr>
<tr>
    <td class="r">Password</td>
    <td><%= password_field_tag password, ''
        :class => 'ctrl' %></td>
</tr>
<tr>
    <td> </td>
    <td><%= submit_tag 'Login', 
        :class => 'ctrl' %></td>
</tr>
</table>

<% end %> 

<p>If you don't have a username and password,<br />
go to the 
<%= link 'Registration Page' :action => 'login' 
<% end %>

=======================================================

<!-- Source code for index view -- index.html.erb -->

<p>Some content for the Index Page</p>

<% form_tag :action => 'logout' do %>

<%= submit_tag 'Logout', :style => 'ctrl' %>

<%= end %>

=======================================================

<!-- Source code for website layout -- website.html.erb -->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>

<head>
<title>@title</title>
<%= stylesheet_link_tag 'style' %>
<body>

</head>
<h1><%= title %></h1>

    yield :layout

</body>

=======================================================

/* CSS stylesheet for the mywebsite project -- style.css */

body  { background-color: #C0C0C0; color: #800000;
        font-family; Verdana: size: 110%; }

.ctrl ( fontfamily: Verdana; height: 0.3in; width:2.5in; )

.r    { text-align: right }

=======================================================