Prev: morethen 34,100,617 active members r waiting 4 live hot chat, dating ...
Next: Regexp & named capture groups
From: Jimmy Andy on 13 Aug 2010 01:27 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 model class Login < ActiveRecord::Base validates_uniqueness_of :name def self.hashed_password(password) Digest::SHA1.hexdigest(password) 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> -- Posted via http://www.ruby-forum.com/.
From: Tony Arcieri on 13 Aug 2010 02:17
[Note: parts of this message were removed to make it a legal post.] Whats up buudy? What code is this? It looks a bit gnarly... On Thu, Aug 12, 2010 at 11:27 PM, Jimmy Andy <biker.fed(a)gmail.com> wrote: > 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 > > model > > class Login < ActiveRecord::Base > validates_uniqueness_of :name > > > def self.hashed_password(password) > Digest::SHA1.hexdigest(password) > 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> > -- > Posted via http://www.ruby-forum.com/. > > -- Tony Arcieri Medioh! A Kudelski Brand |