whats up buudy check out the login controller

Discussion in 'Ruby' started by Jimmy Andy, Aug 13, 2010.

  1. Jimmy Andy

    Jimmy Andy Guest

    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/.
     
    Jimmy Andy, Aug 13, 2010
    #1
    1. Advertising

  2. Jimmy Andy

    Tony Arcieri Guest

    [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 <> 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
     
    Tony Arcieri, Aug 13, 2010
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Davisro
    Replies:
    1
    Views:
    707
    Michael D. Ober
    Jun 14, 2004
  2. Hermit Dave

    Forms Login Page Not Login Out

    Hermit Dave, Jan 12, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    520
    Hermit Dave
    Jan 13, 2004
  3. sincethe2004
    Replies:
    1
    Views:
    804
    sincethe2004
    Jun 22, 2004
  4. Michael Earls
    Replies:
    3
    Views:
    3,389
    MBUnit
    Mar 24, 2009
  5. sincethe2004
    Replies:
    0
    Views:
    163
    sincethe2004
    Jun 22, 2004
Loading...

Share This Page