Skip to content

Commit 27075d5

Browse files
committed
修正单点登录接口,增加成功后的跳转
1 parent 5b96589 commit 27075d5

3 files changed

Lines changed: 47 additions & 25 deletions

File tree

Song.Site/API/SSO.ashx.cs

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,56 +20,57 @@ public class SSO : IHttpHandler
2020
string user = WeiSha.Common.Request.QueryString["user"].String; //用户名
2121
string domain = WeiSha.Common.Request.QueryString["domain"].UrlDecode; //来自请求的域名
2222
string action = WeiSha.Common.Request.QueryString["action"].String; //动作,login登录,logout退出登录
23-
string ret = WeiSha.Common.Request.QueryString["return"].UrlDecode; //返回类型,xml或json
24-
23+
string ret = WeiSha.Common.Request.QueryString["return"].String; //返回类型,xml或json
24+
string goto_url = WeiSha.Common.Request.QueryString["goto"].String; //成功后的跳转地址
2525

2626
public void ProcessRequest(HttpContext context)
2727
{
28-
string reslut = string.Empty;
28+
29+
SSO_State state = null;
2930
try
3031
{
3132
if (string.IsNullOrWhiteSpace(user))
3233
{
33-
reslut = new SSO_State(0, 1, "账号不得为空").ToReturn(ret);
34+
state = new SSO_State(false, 1, "账号不得为空");
3435
}
3536
else
3637
{
3738
Song.Entities.SingleSignOn entity = Business.Do<ISSO>().GetSingle(appid);
38-
if (entity == null) reslut = new SSO_State(0, 2, "接口对象不存在").ToReturn(ret);
39+
if (entity == null) state = new SSO_State(false, 2, "接口对象不存在");
3940
if (entity != null)
4041
{
4142
if (entity.SSO_Domain != domain.ToLower())
4243
{
43-
reslut = new SSO_State(0, 3, "该请求来自的域不合法").ToReturn(ret);
44+
state = new SSO_State(false, 3, "该请求来自的域不合法");
4445
}
4546
else
4647
{
4748
//通过验证,进入登录状态
4849
Song.Entities.Accounts emp = Business.Do<IAccounts>().IsAccountsExist(user);
4950
if (emp == null)
5051
{
51-
reslut = new SSO_State(0, 4, string.Format("当前账号({0})不存在", user)).ToReturn(ret);
52+
state = new SSO_State(false, 4, string.Format("当前账号({0})不存在", user));
5253
}
5354
else
5455
{
5556
if (!emp.Ac_IsPass || !emp.Ac_IsUse)
5657
{
57-
reslut = new SSO_State(0, 5, string.Format("当前账号({0})被禁用或未通过审核", user)).ToReturn(ret);
58+
state = new SSO_State(false, 5, string.Format("当前账号({0})被禁用或未通过审核", user));
5859
}
5960
else
6061
{
6162
if (action == "logout")
6263
{
6364
LoginState.Accounts.Logout();
64-
reslut = new SSO_State(1, 7, string.Format("当前账号({0})退出登录", user)).ToReturn(ret);
65+
state = new SSO_State(true, 7, string.Format("当前账号({0})退出登录", user));
6566
}
6667
else
6768
{
6869
LoginState.Accounts.Write(emp);
6970
//登录成功
7071
Business.Do<IAccounts>().PointAdd4Login(emp, "协同站点登录", domain, ""); //增加登录积分
7172
Business.Do<IStudent>().LogForLoginAdd(emp);
72-
reslut = new SSO_State(1, 6, string.Format("当前账号({0})登录成功", user)).ToReturn(ret);
73+
state = new SSO_State(true, 6, string.Format("当前账号({0})登录成功", user));
7374
}
7475
}
7576
}
@@ -79,10 +80,19 @@ public void ProcessRequest(HttpContext context)
7980
}
8081
catch (Exception ex)
8182
{
82-
reslut = new SSO_State(0, 0, ex.Message).ToReturn(ret);
83+
state = new SSO_State(false, 0, ex.Message);
84+
}
85+
//如果成功,且转向地址不为空,则跳转
86+
if (state.success && !string.IsNullOrWhiteSpace(goto_url))
87+
{
88+
context.Response.Redirect(goto_url);
89+
}
90+
else
91+
{
92+
string reslut = state.ToReturn(ret);
93+
context.Response.Write(reslut);
94+
context.Response.End();
8395
}
84-
context.Response.Write(reslut);
85-
context.Response.End();
8696
}
8797

8898
public bool IsReusable
@@ -95,19 +105,29 @@ public bool IsReusable
95105
}
96106
public class SSO_State
97107
{
98-
//成功success=1,失败为0
99-
public int success { get; set; }
100-
//状态码
108+
/// <summary>
109+
/// 是否成功
110+
/// </summary>
111+
public bool success { get; set; }
112+
/// <summary>
113+
/// 状态码
114+
/// </summary>
101115
public int state { get; set; }
102-
//提示信息
116+
/// <summary>
117+
/// 提示信息
118+
/// </summary>
103119
public string msg { get; set; }
104120
/// <summary>
121+
/// 成功后需要转向的地址
122+
/// </summary>
123+
public string goto_url { get; set; }
124+
/// <summary>
105125
/// 构造方法
106126
/// </summary>
107127
/// <param name="succ"></param>
108128
/// <param name="state"></param>
109129
/// <param name="msg"></param>
110-
public SSO_State(int succ, int state, string msg)
130+
public SSO_State(bool succ, int state, string msg)
111131
{
112132
this.success = succ;
113133
this.state = state;

Song.Site/Manage/Site/SSOApi_Edit.aspx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,15 @@
6262
</td>
6363
<td>
6464
1、示例:<br />
65-
http://当前系统的域名/api/sso.ashx?appid=xx&user=xx&domain=xx&action=login|logout&return=xml|json
65+
http://当前系统的域名/api/sso.ashx?appid=xx&domain=xx&user=xx&action=login|logout&return=xml|json&goto=(url)
6666
<br />
6767
2、参数说明:<br />
68-
user:用户账号名<br />
69-
domain:请求此调用的来源网站域名<br />
70-
action:登录还是退出登录<br />
71-
return:返回值是xml还是json格式<br />
68+
appid:应用ID<br />
69+
domain:请求域,请求此调用的来源网站域名,需Url编码<br />
70+
user:用户账号名<br />
71+
action:登录还是退出登录(可以为空),默认为login<br />
72+
return:返回值是xml还是json格式(可以为空),默认为xml格式<br />
73+
goto:成功后的转向地址(可以为空),转到首页用/,如果失败将不跳转
7274
</td>
7375
</tr>
7476
<tr>
@@ -83,7 +85,7 @@
8385
</td>
8486
<td>
8587
返回值为xml或json,但关键值相同:<br />
86-
success:1为成功,0为失败<br />
88+
success:true为成功,false为失败<br />
8789
msg:提示信息
8890
</td>
8991
</tr>

Song.Site/Song.Site.csproj.user

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<VisualStudio>
88
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
99
<WebProjectProperties>
10-
<StartPageUrl>Manage/Tester.aspx</StartPageUrl>
10+
<StartPageUrl>Default.aspx</StartPageUrl>
1111
<StartAction>SpecificPage</StartAction>
1212
<AspNetDebugging>True</AspNetDebugging>
1313
<SilverlightDebugging>False</SilverlightDebugging>

0 commit comments

Comments
 (0)