OpenAuth.Net/OpenAuth.Mvc/Controllers/LoginController.cs
小色 ffb40b28c1 拿掉地址栏Token,因为特别不安全。
小王,xxx系统的地址是多少。。。然后账号就泄露了

缺点是Token不能跨域。

OpenAuth.WebApi\Web.config
修改一个provider标签MySql.Data.MySqlClient
使用vs自带功能整理了一下格式。
2017-12-24 17:55:02 +08:00

93 lines
2.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Configuration;
using System.Web.Mvc;
using Infrastructure;
using OpenAuth.App.SSO;
using System.Web;
namespace OpenAuth.Mvc.Controllers
{
public class LoginController : Controller
{
private string _appKey = ConfigurationManager.AppSettings["SSOAppKey"];
// GET: Login
public ActionResult Index()
{
ViewBag.AppKey = _appKey;
return View();
}
[HttpPost]
public string Index(string username, string password)
{
var resp = new LoginResult();
try
{
var result = AuthUtil.Login(_appKey, username, password);
if (result.Code == 200)
{
var cookie = new HttpCookie("Token", result.Token)
{
Expires = DateTime.Now.AddDays(10)
};
Response.Cookies.Add(cookie);
resp.Result = "/home/index";
///拿掉地址栏Token因为特别不安全。
///小王xxx系统的地址是多少。。。然后账号就
}
else
{
resp.Message = "登录失败";
}
}
catch (Exception e)
{
resp.Code = 500;
resp.Message = e.Message;
}
return JsonHelper.Instance.Serialize(resp);
}
/// <summary>
/// 开发者登录
/// </summary>
public ActionResult LoginByDev()
{
try
{
var result = AuthUtil.Login(_appKey, "System", "123456");
if (result.Code == 200)
{
var cookie = new HttpCookie("Token", result.Token)
{
Expires = DateTime.Now.AddDays(10)
};
Response.Cookies.Add(cookie);
return Redirect("/home/index");
///拿掉地址栏Token因为特别不安全。
///小王xxx系统的地址是多少。。。然后账号就
}
else
{
return RedirectToAction("Index", "Login");
}
}
catch (Exception e)
{
return RedirectToAction("Index", "Login");
}
}
public ActionResult Logout()
{
AuthUtil.Logout();
return RedirectToAction("Index", "Login");
}
}
}