你的位置:首页 > 软件开发 > ASP.net > netMVC 搭建Ucenter 同步登陆退出discuz

netMVC 搭建Ucenter 同步登陆退出discuz

发布时间:2015-06-22 00:00:28
先看一下效果首先准备材料:1.ucenter for net :https://github.com/dozer47528/UCenter-API-For-DotNet or http://pan.baidu.com/s/1i3znQV72.uc.ashx 下面是具体代码u ...

先看一下效果

netMVC 搭建Ucenter 同步登陆退出discuz

首先准备材料:

1.ucenter for net :https://github.com/dozer47528/UCenter-API-For-DotNet or http://pan.baidu.com/s/1i3znQV7

2.uc.ashx  下面是具体代码

using DS.Web.UCenter;using DS.Web.UCenter.Api;using DS.Web.UCenter.Client;using log4net;using pc_manishi.Controllers;using System;using System.Collections.Generic;using System.Linq;using System.Web;namespace pc_manishi.API{  /// <summary>  /// Summary description for uc  /// </summary>  public class uc : UcApiBase  {    HttpResponse Response = HttpContext.Current.Response;    HttpRequest Request = HttpContext.Current.Request;    private static readonly ILog logger = LogManager.GetLogger(typeof(AddressController));    public override ApiReturn DeleteUser(IEnumerable<int> ids)    {      throw new NotImplementedException();    }    public override ApiReturn RenameUser(int uid, string oldUserName, string newUserName)    {      throw new NotImplementedException();    }    public override UcTagReturns GetTag(string tagName)    {      throw new NotImplementedException();    }    //登陆    public override ApiReturn SynLogin(int uid)    {      try      {        IUcClient client = new UcClient();        UcUserInfo user = client.UserInfo(uid);        if (user.Success)        {          //LoggerCore.Debug(user.Uid + "--" + user.UserName);          HttpContext.Current.Session["uid"] = user.Uid;          HttpContext.Current.Session["username"] = user.UserName;          HttpContext.Current.Session["email"] = user.Mail;          return ApiReturn.Success;        }        return ApiReturn.Failed;      }      catch (Exception ex)      {        logger.Error("远程登录错误", ex);        return ApiReturn.Failed;      }      //throw new NotImplementedException();    }    //登出    public override ApiReturn SynLogout()    {      try      {        logger.Error("论坛正在登出操作");        //HttpContext.Current.Session.Abandon();      }      catch (Exception ex)      {        logger.Error("远程退出错误", ex);      }      return ApiReturn.Success;     //throw new NotImplementedException();    }    public override ApiReturn UpdatePw(string userName, string passWord)    {      throw new NotImplementedException();    }    public override ApiReturn UpdateBadWords(UcBadWords badWords)    {      throw new NotImplementedException();    }    public override ApiReturn UpdateHosts(UcHosts hosts)    {      throw new NotImplementedException();    }    public override ApiReturn UpdateApps(UcApps apps)    {      throw new NotImplementedException();    }    public override ApiReturn UpdateClient(UcClientSetting client)    {      throw new NotImplementedException();    }    public override ApiReturn UpdateCredit(int uid, int credit, int amount)    {      throw new NotImplementedException();    }    public override UcCreditSettingReturns GetCreditSettings()    {      throw new NotImplementedException();    }    public override ApiReturn GetCredit(int uid, int credit)    {      throw new NotImplementedException();    }    public override ApiReturn UpdateCreditSettings(UcCreditSettings creditSettings)    {      throw new NotImplementedException();    }  }}
接下来就是同步登陆了:其实就是调用了一下 IUcClient类的方法,然后通过usersynlogin来拿到远程登陆的js代码,我这里不知道为什么,用  Response.Write() 来输出到前端,但我这里返回到了所以我这里用webhttprequest进行了一部处理,原理就是返回的js里面有个src,你直接在浏览器访问一下就把要登陆的cookie下来了,但要注意cookie的域名要设置二级域名共享,退出的话也是同样的处理再说一下注册:注册这里我关闭了验证码,去掉了邮箱必填(度娘可以告诉你怎么关闭)也需要登陆一下让discuz自动激活你的用户下面再说一下搬家的注意事项(我这里从winserver 搬到了linux上):文章写的不是很详细,大家多多见谅公司里的php,linux同事

原标题:netMVC 搭建Ucenter 同步登陆退出discuz

关键词:net

net
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。