本文整理汇总了C#中IServiceBase.GetSessionId方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceBase.GetSessionId方法的具体用法?C# IServiceBase.GetSessionId怎么用?C# IServiceBase.GetSessionId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IServiceBase
的用法示例。
在下文中一共展示了IServiceBase.GetSessionId方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryAuthenticate
public override bool TryAuthenticate(IServiceBase authService, string userName, string password)
{
var Roles = new List<string>();
var Permissions = new List<string>();
var dbConnectionFactory =
new OrmLiteConnectionFactory("Server = localhost; Database = auth; Uid = root; Pwd = 123",
MySqlDialect.Provider);
using (var db = dbConnectionFactory.Open())
{
LoginModels user = db.Query<LoginModels>("Select * from loginmodels where [email protected]",new{userName = userName}).SingleOrDefault();
if (user==null)
{
return false;
}
if (password!=user.Pass)
{
return false;
}
//Get All the roles per user
List<Roles> roleses = db.Query<Roles>("SELECT `Join1`.`ROLE_ID1` AS `role_Id`, `Join1`.`Name` FROM `LoginModels` AS `Extent1` INNER JOIN (SELECT `Extent2`.`lm_Id`, `Extent2`.`role_Id`, `Extent3`.`role_Id` AS `ROLE_ID1`, `Extent3`.`Name` FROM `login_roles` AS `Extent2` INNER JOIN `Roles` AS `Extent3` ON `Extent3`.`role_Id` = `Extent2`.`role_Id`) AS `Join1` ON `Extent1`.`lm_Id` = `Join1`.`lm_Id` WHERE `Extent1`.`User`[email protected]",new { userName = userName });
foreach (var role in roleses)
{
Roles.Add(role.Name);
List<Permissions> permis = db.Query<Permissions>("SELECT `Join1`.`permi_Id`, `Join1`.`Name` FROM `Roles` AS `Extent1` INNER JOIN (SELECT `Extent2`.`role_id`, `Extent2`.`per_id`, `Extent3`.`permi_Id`, `Extent3`.`Name` FROM `roles_permissions` AS `Extent2` INNER JOIN `Permissions` AS `Extent3` ON `Extent3`.`permi_Id` = `Extent2`.`per_id`) AS `Join1` ON `Extent1`.`role_Id` = `Join1`.`role_id` WHERE `Extent1`.`Name` [email protected]_name ", new { role_name = role.Name });
foreach (var permi in permis)
{
Permissions.Add(permi.Name);
}
}
}
var session = authService.GetSession(false);
//Add Repository Method for Validate User if there's one.
//if (!Membership.ValidateUser(userName, password)) return false;
session.IsAuthenticated = true;
session.Id = authService.GetSessionId();
if (session.UserAuthId == null)
session.UserAuthId = userName;
session.Roles = Roles; //loaded from db
session.Permissions = Permissions; //loaded from db
if (session.HasRole("admin"))
{
session.ReferrerUrl = "/api"; //Redirect to Admin Role to the api page
}
return true;
}
示例2: AuthenticateResponseDecorator
public object AuthenticateResponseDecorator(IServiceBase authService, Authenticate request, AuthenticateResponse authResponse)
{
if (authResponse.BearerToken == null || request.UseTokenCookie != true)
return authResponse;
authService.Request.RemoveSession(authService.GetSessionId());
return new HttpResult(authResponse)
{
Cookies = {
new Cookie(Keywords.TokenCookie, authResponse.BearerToken, Cookies.RootPath) {
HttpOnly = true,
Secure = authService.Request.IsSecureConnection,
Expires = DateTime.UtcNow.Add(ExpireTokensIn),
}
}
};
}