class LoginController < ApplicationController
def addprod
@category=Cattab1.find(:all)
@product=Prodtab.find(:all)
@i=0
@checkvalue=""
end
def login
@logincheck =Login.new
@prodcheck=Prodtab.new
if(session[:login_id])
Login.update(session[:login_id],:user_status=>"0")
end
end
def login_create
@login = Login.new(params[:login])
if request.get?
session[:login_id] = nil
else
puts ''logincretaeeeeeeeeeeeeeeeeeeeeeeeeee''
puts params[:login][:password]
params[:login][:password]
Login.hashed_password(params[:login][:password])
puts params[:login][:password]
@logincheck
Login.find_by_name_and_password(params[:login][:name],params[:login][:password])
if @logincheck == nil
#@logincheck.save
flash[:error] ="Name/Password not matching"
redirect_to :controller=>''login'',
:action=>''login'' and
return
else
session[:login_id] = @logincheck.id
Login.update(@logincheck.id,:user_status=>"1")
redirect_to :controller=>''prodtabs'',
:action=>''index''
and return
end
end
end
def category3
puts ''*****category3****''
@categyid=request.raw_post
session[:category_id]=@categyid.to_i
puts @categyid.to_i
@catlist=Cattab1.find_all_by_id(@categyid.to_i)
end
def category4
puts ''*****category4****''
@productid=request.raw_post
puts @productid.to_i
@prodlist=Prodtab.find_all_by_id(@productid.to_i)
end
def prod1
puts ''*******prodids********''
puts params[:product_id]
puts ''*********vijay********''
@prodcheck1=params[:product_id]
@prodcheck=Prodtab.find_all_by_id(@prodcheck1)
@prodcheckcatid=Prodtab.find_all_by_cattab1_id(@prodcheck1)
@prodcheck.each do|p|
if p.cattab1_id==0
Prodtab.update(p.id ,:cattab1_id=>session[:category_id])
flash[:success] ="Product is assigned successfully"
else
flash[:error] ="#{p.pname} is already assigned"
redirect_to :controller=>''login'',
:action=>''addprod'' and
return
end
#end
end
redirect_to:controller=>''login'',
:action=>''addprod''
end
end
views
<script type="text/javascript">
var txt1=new Array();
var txt2=new Array();
function compare1()
{
if(document.getElementById("login_name").value=="")
{
alert("Please enter the Login name");
document.getElementById("login_name").focus();
return false;
}
var checkStr = document.getElementById("login_name").value;
if(checkStr.length<2 || checkStr.length>6)
{
alert("Login Name should be minimum two characters and maximum
Six characters");
document.getElementById("login_name").value="";
document.getElementById("login_name").focus();
return false;
}
var checkOK
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
var checkStr1= document.getElementById("login_name").value;
var checkStr2= document.getElementById("login_password").value;
var allValid = true;
var allValid1=true;
for (i = 0; i < checkStr.length; i++)
{
ch = checkStr.charAt(i);
for (j = 0; j < checkOK.length; j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false; break;
}
}
if (!allValid)
{
alert("Please enter only letter and numeric characters in the
\"Login Name\" field.");
document.getElementById("login_name").focus();
document.getElementById("login_name").value="";
return false;
}
if(document.getElementById("login_password").value=="")
{
alert("Please enter the Login Password");
document.getElementById("login_password").focus();
return false;
}
if(checkStr2.length<6 || checkStr2.length>10)
{
alert("Password should be minimum six characters and maximum
Ten characters");
document.getElementById("login_password").value="";
document.getElementById("login_password").focus();
return false;
}
return true;
}
</script>
<html>
<body style="background-color:#F7E4BA">
<b><h6 align="right"></h6>
<h3 align="center"><b> <font
color="maroon">LOGIN FORM</font
color></b></h3>
<center><p style="color:red"><%= flash[:error]
%></p></center>
<table align="center">
<tr>
<% form_tag({ :controller => "login", :action =>
"login_create"}, {:id=>"login",
:name=>"login" ,:multipart => true}) do
%>
<tr><td><b>Login ID </b></td>
<td><%= text_field
''login'',''name'' %></td>
</tr>
<tr><td><b> Password </b></td>
<td><%= password_field
''login'',''password'' %></td>
</tr>
<tr>
<td></td><td align="left"> <input
type="submit" value="Login"
onclick ="return compare1();"><!--<%= submit_tag
''Login'' %>-->
<input type="reset"
value="Clear"></td></tr>
<% end %>
</table>
</body>
</html>
model
class Login < ActiveRecord::Base
validates_uniqueness_of :name
def self.hashed_password(password)
Digest::SHA1.hexdigest(password)
end
end
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.