In my application, I have a "user" table which have following structure.

在我的应用程序中,我有一个“用户”表,它具有以下结构。

CREATE TABLE IF NOT EXISTS `users` (
  `userId` int(10) unsigned NOT NULL auto_increment,
  `username` varchar(128) NOT NULL default '',
  `password` varchar(32) NOT NULL default '',
  `email` text NOT NULL,
  `newsletter` tinyint(1) NOT NULL default '0',
  `banned` enum('yes','no') NOT NULL default 'no',
  `admin` enum('yes','no') NOT NULL default 'no',
  `signup_ip` varchar(20) NOT NULL default '',
  `activation_key` varchar(60) NOT NULL default '',
  `resetpassword_key` varchar(60) NOT NULL default '',
  `createdon` datetime NOT NULL default '0000-00-00 00:00:00',
  PRIMARY KEY  (`userId`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=27 ;

I want to implement social login via facebook, twitter and openid in my application, just like StatckOverflow did. Please suggest me what all change I will require in my db and how the logic will be implemented in PHP, alongside with existing login facility.

我想在我的应用程序中通过facebook,twitter和openid实现社交登录,就像StatckOverflow一样。请建议我在我的数据库中需要做什么改变,以及如何在PHP中实现逻辑,以及现有的登录工具。

Thanks!

谢谢!

2 个解决方案

#1


24

I would suggest that you introduce the concept of an AuthenticationProvider:

我建议你介绍一下AuthenticationProvider的概念:

CREATE TABLE IF NOT EXISTS `AuthenticationProvider` (
`ProviderKey` varchar(128) NOT NULL,
`userId` int(10) unsigned NOT NULL,
`ProviderType` enum('facebook','twitter', 'google') NOT NULL, 
PRIMARY KEY  (`ProviderKey`) )  
ENGINE=MyISAM  DEFAULT CHARSET=latin1;

Each login provider provides a unique key for the user. This is stored in ProviderKey. The ProviderType contains information about which login provider this ProviderKey belongs to, and finally, the userId column couples the information with the users table. So when you receive a succesful login from one of the login providers you find the corresponding ProviderKey in the table and use set the authentication cookie for the user in question.

每个登录提供程序都为用户提供唯一的密钥。它存储在ProviderKey中。 ProviderType包含有关此ProviderKey属于哪个登录提供程序的信息,最后,userId列将信息与users表耦合。因此,当您从其中一个登录提供程序收到成功登录时,您会在表中找到相应的ProviderKey,并使用为相关用户设置身份验证cookie。

I'm not sure that you want the ProviderType to be an enum. It would probably be more correct to make another table that could hold these.

我不确定您是否希望ProviderType成为枚举。制作另一个可以容纳这些的表可能更为正确。

When a user first registers with your site, and logs in via Facebook, for example, you will have to create a row in the users table. However, there will be no password, activation_key and resetpassword_key involved. So you may want to move those fields to a separate table, such that your users table only contains the core user data, and no data that is only relevant for a single login mechanism (username/password).

例如,当用户首次向您的站点注册并通过Facebook登录时,您必须在users表中创建一行。但是,不会涉及密码,activation_key和resetpassword_key。因此,您可能希望将这些字段移动到单独的表中,以使您的users表仅包含核心用户数据,而不包含仅与单个登录机制(用户名/密码)相关的数据。

I hope this makes sense and that it points you in the right direction.

我希望这是有道理的,并指出你正确的方向。

/Klaus

/克劳斯

更多相关文章

  1. 如何区分socket.io聊天中的Symfony用户角色/组
  2. php微信网页授权获取用户信息
  3. Laravel Auth只验证管理员/超级用户
  4. 用户GROUP BY ERROR之间的SQL查询privatemsgs
  5. 使用PHP显示用户输入
  6. 根据网址上的国家/地区将用户重定向到正确的数据库,我使用i18n fo
  7. PHP结合Redis来限制用户或者IP某个时间段内访问的次数
  8. 使用JOIN获取有关两个用户的信息
  9. PHP:如果用户没有按下提交按钮,则Mysql回滚多个查询(通过ajax完成)

随机推荐

  1. 利用XSLT把ADO记录集转换成XML
  2. XPath 11个实例
  3. XML 问题: 超越DOM(轻松使用 DOM 的技巧
  4. 从xml中获取城市,省份名称
  5. 使用 XML 文件记录操作日志
  6. XMLTextReader和XmlDocument读取XML文件
  7. XML和XSLT结合使网站设计浑然一体
  8. 对于任意的XML的遍历
  9. 如何使用XML实现多渠道接入网站的构架
  10. 灵活调用xsl来解析xml文档(js异步)