OAuth2 通用组件源代码实例下载(支持新浪微博、QQ、淘宝登陆),拿来就能用哦
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
litOtherLoginInfo.Text = OAuth2.UI.GetHtml();
if (IsPostBack)
{
return;
}
OAuth2.OAuth2Base ob = OAuth2.OAuth2Factory.Current;//获取当前的授权类型,如果成功,则会缓存到Session中。
if (ob != null) //说明用户点击了授权,并跳回登陆界面来
{
string account = string.Empty;
if (ob.Authorize(out account))//检测是否授权成功,并返回绑定的账号(具体是绑定ID还是用户名,你的选择)
{
if (!string.IsNullOrEmpty(account))//已绑定账号,直接用该账号设置登陆。
{
UserLogin ul = new UserLogin();
if (ul.Login(account))
{
Response.Redirect("/");
}
}
else // 未绑定账号,引导提示用户绑定账号。
{
Response.Write(ob.nickName " 首次使用需要绑定网站账号,请登陆或注册新账号");
}
}
}
else // 读取授权失败。
{
//提示用户重试,或改用其它社区方法登陆。
}
}
protected void btnLogin_Click(object sender, EventArgs e)
{
UserLogin ul = new UserLogin();
if (ul.Login(txtUserName.Text, txtPassword.Text))
{
//登陆成功后,增加两行逻辑,检测是否绑定了账号
OAuth2.OAuth2Base ob = OAuth2.OAuth2Factory.SessionOAuth;
if (ob != null && !string.IsNullOrEmpty(ob.openID))
{
ob.SetBindAccount(txtUserName.Text);
}
Response.Redirect("/");//登陆后跳转
}
}
protected void btnReg_Click(object sender, EventArgs e)
{
UserLogin ul = new UserLogin();
if (ul.Reg(txtUserName.Text, txtPassword.Text))
{
//注册成功后,增加两行逻辑,检测是否绑定了账号 -- 代码和登陆的一样。
OAuth2.OAuth2Base ob = OAuth2.OAuth2Factory.SessionOAuth;
if (ob != null && !string.IsNullOrEmpty(ob.openID))
{
ob.SetBindAccount(txtUserName.Text);
}
Response.Redirect("/");//登陆后跳转
}
}
}
public class UserLogin
{
/// <summary>
/// 授权时直接用用户名登陆。
/// </summary>
public bool Login(string userName)
{
return true;
}
public bool Login(string userName, string password)
{
return true;
}
public bool Reg(string userName, string password)
{
return true;
}
}
资源文件列表
OAuth2/OAuth2.csproj , 2622
OAuth2/OAuth2Base.cs , 6736
OAuth2/OAuth2Config.cs , 136
OAuth2/OAuth2Factory.cs , 2837
OAuth2/OAuths/QQOAuth.cs , 3608
OAuth2/OAuths/SinaWeiBoOAuth.cs , 3828
OAuth2/OAuths/TaoBaoAuth.cs , 2398
OAuth2/OAuthTable/OAuth2Account.cs , 2853
OAuth2/Properties/AssemblyInfo.cs , 1457
OAuth2/Tool/Tool.cs , 3215
OAuth2/UI/UI.cs , 746
OAuth2/外置的文本数据库操作类dll/CYQ.Data.dll , 233472
OAuth2/外置的文本数据库操作类dll/CYQ.Data.xml , 130977
OAuth2Demo/bin/CYQ.Data.dll , 233472
OAuth2Demo/bin/CYQ.Data.xml , 130977
OAuth2Demo/bin/OAuth2.dll , 28672
OAuth2Demo/bin/OAuth2.xml , 6259
OAuth2Demo/bin/OAuth2Demo.dll , 16384
OAuth2Demo/Login.aspx , 1647
OAuth2Demo/Login.aspx.cs , 3346
OAuth2Demo/Login.aspx.designer.cs , 2697
OAuth2Demo/OAuth2Demo.csproj , 3770
OAuth2Demo/OAuth2Demo.csproj.user , 1150
OAuth2Demo/Properties/AssemblyInfo.cs , 1332
OAuth2Demo/skin/system_tech/images/oauth_qq.png , 1851
OAuth2Demo/skin/system_tech/images/oauth_sinaweibo.png , 3412
OAuth2Demo/skin/system_tech/images/oauth_taobao.png , 219
OAuth2Demo/Web.config , 2015
OAuth2Demo.sln , 1691
OAuth2Demo.suo , 19050
OAuth2Demo/使用说明.txt , 214
