Re: problems creating a simple auth, please help.

rek2
2008-03-17T18:23:07Z

Hi, sorry I must to have missed your other email..
but if that is the only issue then why is not doing anythign at all?
I mean it should "flash" me that the user/passwod was wrong.. this is
why I suspect
there  is something mayor that I am not doing right here..

Thanks for your response hopefully someone can help me with this.


ReK2 escribió:
> Hi, I am new to ruby/rails. learning fast but still getting stuck on key
> places..
> so I have a db and a column called email and crypt one is obviously the
> email of the users and the other the password column.
> so I have this controller for the main application controller:
> -----
> protected
>    def login_required
>      session[:auth] ? yield : render(:template =>
''login/login'')
>    end
> -----
>
> this login controller:
>
> -----
> skip_filter :login_required
>
>  def logout(msg = "")
>    reset_session
>    flash[:notice] = msg if msg.length
>    redirect_to ''/''
>  end
>
>  def check
>    if not request.post?
>      logout("Invalid request.")
>        elsif session[:auth] = Login.authenticate(params[:email,
> params[:crypt])
>      redirect_to :back
>    else
>      logout("Your user name and password are invalid.")
>    end
>  end
>
> -------
>
> and this as model:
>
> set_table_name "users"   # this is because the table is not named
login
> but users I have another model called users for something else.
>
>        validates_presence_of :email
>
>        def self.authenticate(email, crypt)
>        password = crypt
>        if email
>                salt =
[Array.new(6){rand(256).chr}.join].pack("m").chomp
>                expected_password = password.crypt(salt)
>                if Users.crypt != expected_password
>                email = nil
>        end
>        end
>                email
>        end
> ----------
>
> and here is my views:
>
>
>
> <%= error_messages_for ''login'' %>
>
>
> Enter your email and password
> <% form_tag do %>
>
> Email
>        <%= text_field_tag :email, params[:email]  %>
>
>
>
> Password
>        <%= password_field_tag :crypt, params[:crypt]  %>
>
> <%= submit_tag "Login" %>
> <% end %>
>
>
>
>
> the issue: I see the form.. that is easy ;-)
> but I put in a real email and password and does not work..
> when I put a wrong one it does not give me the result I expect..
>
> I use the path and no matter were I go it will redirect me to the
> login(this is good)
> www.domain.org/login
>
>
> Any help will be VERY appreciated.
>
> Thanks
>
> >
>


--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe@googlegroups.com