Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Validate fields (password, login) depending on the type of user
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
ChrisRichards  
View profile  
 More options Nov 30 2010, 8:44 am
From: ChrisRichards <evilgeen...@gmail.com>
Date: Tue, 30 Nov 2010 05:44:18 -0800 (PST)
Local: Tues, Nov 30 2010 8:44 am
Subject: Validate fields (password, login) depending on the type of user
Hi

I am using the same user model for all the different types of users in
my rails app.  Most of the time I want to validate the login and
password details but in some other situations I am not using the login
and password fields so I don't want to validate them.

Is there a way to turn validations off in certain circumstances?

Thanks
Chris


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
gezope  
View profile  
 More options Dec 1 2010, 7:39 am
From: gezope <gez...@gmail.com>
Date: Wed, 1 Dec 2010 04:39:55 -0800 (PST)
Local: Wed, Dec 1 2010 7:39 am
Subject: Re: Validate fields (password, login) depending on the type of user
Hello Chris,

you usually do your validates in your model, here is a good guide for
it:
http://guides.rubyonrails.org/active_record_validations_callbacks.html

So many types of validations, like validates_presence_of or
validates_numerilacity_of, etc. and you can also write your own
validations if you want.

If you want to turn it of maybe it's a good idea to give an if clause
after it, to ensure those circumstances are exists.

I also found this:
http://stackoverflow.com/questions/279478/how-can-i-disable-a-validat...

You want to turn off validations in general? May I ask why?

I'm interested in your solution, it seems an interesting issue, please
let me know.
good luck,
Zoltan

On nov. 30, 13:44, ChrisRichards <evilgeen...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
ChrisRichards  
View profile  
 More options Dec 2 2010, 8:01 am
From: ChrisRichards <evilgeen...@gmail.com>
Date: Thu, 2 Dec 2010 05:01:47 -0800 (PST)
Local: Thurs, Dec 2 2010 8:01 am
Subject: Re: Validate fields (password, login) depending on the type of user
Hi Zoltan

> You want to turn off validations in general? May I ask why?

I only want to turn off validations for one type of user, which are
the survey participants.  The survey participants do not log in with a
username and password, they are sent a link in an email, like this :

http://site.com/login/jjk89ykjh9y9y9h9yy9y89121

Where jjk89ykjh9y9y9h9yy9y89121 is a UUID.
So their user accounts do not have a login or password.

This is my solution

class User < ActiveRecord::Base

  ADMIN = "admin"
  SITE_ADMIN = "site_admin"
  COMPANY_USER = "company_user"
  SITE_TRANSLATOR = "site_translator"
  ANSWER_TRANSLATOR = "answer_translator"
  PARTICIPANT = "participant"
  ROLES = [ADMIN, SITE_ADMIN, COMPANY_USER, SITE_TRANSLATOR,
ANSWER_TRANSLATOR, PARTICIPANT]

  acts_as_authentic do |c|
    #only validate password if the user is the correct type of user.
    #Participant users don't use login/password

c.merge_validates_format_of_login_field_options :if=>:requires_login_details

c.merge_validates_length_of_login_field_options :if=>:requires_login_details

c.merge_validates_confirmation_of_password_field_options :if=>:validate_password?

c.merge_validates_length_of_password_confirmation_field_options :if=>:validate_password?

c.merge_validates_length_of_password_field_options :if=>:validate_password?
  end

  private

  def validate_password?
    new_record? ?  requires_login_details : password.present? ||
password_confirmation.present?
  end

  #determine if user needs to have login/password
  #& = array intersection method
  def requires_login_details
    (roles & [ADMIN, SITE_ADMIN, COMPANY_USER]).any?
  end

  def roles
    (user_roles||"").split(" ")
  end

On Dec 1, 12:39 pm, gezope <gez...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »