简体   繁体   中英

Rails omniauth-facebook generate random email

About ten to fifteen percent of my users that attempt to login with facebook are unable to do so. Rails give an "email can not be blank" error when trying to create the user.

I used to get a "password can not be blank" error... but I simply had a random password generated whenever facebook wasn't passing one. So I was wondering if there was a way I could generate a random email whenever facebook fails to pass it on?

It was actually easier than I thought:

user.email = auth.info.email = "#{auth.uid}@facebook.com"

That way it works both ways. If it finds the email from omniauth... then it uses that. If it doesn't find it in omniauth... then it takes the user id... put it in front of "@facebook.com" and VOILA! Not-so-randomly generated email address.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM