<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>app/views/layouts/_check_availability.rhtml</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -7,6 +7,15 @@ class ApplicationController &lt; ActionController::Base
   # See ActionController::RequestForgeryProtection for details
   # Uncomment the :secret if you're not using the cookie session store
   protect_from_forgery # :secret =&gt; '707a4952295d1c5b3fb29c6e90697724'
+
+	helper_method :current_user, :logged_in?
+	def current_user
+    @current_user ||= User.find_by_id(session[:user_id])
+  end
+
+	def logged_in?
+	 current_user != nil
+	end
   
   # See ActionController::Base for details 
   # Uncomment this to filter the contents of submitted sensitive data parameters</diff>
      <filename>app/controllers/application.rb</filename>
    </modified>
    <modified>
      <diff>@@ -36,6 +36,23 @@ class LoginController &lt; ApplicationController
   end
 
   def login
+    session[:user_id] = nil
+    if request.post?
+      user = User.authenticate(params[:username], params[:password])
+      if user
+				session[:user_id] = user.id
+				redirect_to(:action =&gt; &quot;index&quot;, :controller =&gt; :login )
+      else
+        flash.now[:error] = &quot;Enter valid username/password&quot;
+	      render(:action =&gt; &quot;login&quot; )
+      end
+    end 
+  end
+
+  def logout
+    session[:user_id] = nil
+    flash[:notice] = &quot;You have successfully Logged out&quot;
+    redirect_to(:action =&gt; &quot;login&quot; )	  
   end
 
 end</diff>
      <filename>app/controllers/login_controller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,6 +2,8 @@ class User &lt; ActiveRecord::Base
 	require 'digest/sha1'
 
 	validates_presence_of	:username, :firstname, :lastname, :email
+  validates_format_of :email,
+                      :with =&gt; /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
 	validates_uniqueness_of	:username, :email
 	
 	attr_accessor :password_confirmation
@@ -18,6 +20,17 @@ class User &lt; ActiveRecord::Base
 		self.hashed_password = User.encrypted_password(self.password, self.salt)
 	end
 
+	def self.authenticate(username, password)
+		user = self.find_by_username(username)
+		if user
+			expected_password = encrypted_password(password, user.salt)
+			if user.hashed_password != expected_password
+				user = nil
+			end
+		end
+		user
+	end
+
   private
 
 	def self.encrypted_password(password, salt)</diff>
      <filename>app/models/user.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,2 +1,3 @@
 &lt;h1&gt;Login#index&lt;/h1&gt;
-&lt;p&gt;Find me in app/views/login/index.html.erb&lt;/p&gt;
+&lt;p&gt;&lt;%= &quot;welcome #{current_user.username}, u r logged in!&quot;%&gt;&lt;/p&gt;
+&lt;%= link_to 'Logout', :action =&gt; &quot;logout&quot;, :controller =&gt; :login %&gt;</diff>
      <filename>app/views/login/index.html.erb</filename>
    </modified>
    <modified>
      <diff>@@ -1,2 +1,21 @@
-&lt;h1&gt;Login#login&lt;/h1&gt;
-&lt;p&gt;Find me in app/views/login/login.html.erb&lt;/p&gt;
+&lt;div class=&quot;loginarea&quot;&gt;
+  &lt;fieldset&gt;
+    &lt;legend&gt;Enter Login Details&lt;/legend&gt;
+    &lt;% form_tag do %&gt;
+			&lt;div&gt;
+		     &lt;p&gt;
+		       &lt;label for=&quot;username&quot; class=&quot;left&quot; style=&quot;width:40%;&quot;&gt;UserName:&lt;/label&gt;
+		       &lt;%= text_field_tag :username, params[:username] %&gt;
+		     &lt;/p&gt;
+		     &lt;p&gt;
+		       &lt;label for=&quot;password&quot; class=&quot;left&quot; style=&quot;width:40%;&quot;&gt;Password:&lt;/label&gt;
+		       &lt;%= password_field_tag :password, params[:password] %&gt;
+		     &lt;/p&gt;
+			 &lt;/div&gt;
+       &lt;p&gt;
+         &lt;%= submit_tag &quot;Login&quot; %&gt;
+				 &lt;%= link_to 'NewUser', :action =&gt; &quot;new&quot;, :controller =&gt; :login %&gt;
+       &lt;/p&gt;  
+    &lt;% end %&gt;
+  &lt;/fieldset&gt;
+&lt;/div&gt;</diff>
      <filename>app/views/login/login.html.erb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>b872fdc0794e35873244ad6b87e4bc080bd5b1b3</id>
    </parent>
  </parents>
  <author>
    <name>Payal Gupta</name>
    <email>cool.payal1985@gmail.com</email>
  </author>
  <url>http://github.com/payalgupta/todo-list/commit/0619471b221332da38decda84383086bd4677c88</url>
  <id>0619471b221332da38decda84383086bd4677c88</id>
  <committed-date>2008-07-17T23:00:47-07:00</committed-date>
  <authored-date>2008-07-17T23:00:47-07:00</authored-date>
  <message>Login/Logout Functionality</message>
  <tree>8f41fa0353397bc5e20a0b8f51cbfc59a9eac07a</tree>
  <committer>
    <name>Payal Gupta</name>
    <email>cool.payal1985@gmail.com</email>
  </committer>
</commit>
