本文整理汇总了C#中IAuthSession.ConvertTo方法的典型用法代码示例。如果您正苦于以下问题:C# IAuthSession.ConvertTo方法的具体用法?C# IAuthSession.ConvertTo怎么用?C# IAuthSession.ConvertTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAuthSession
的用法示例。
在下文中一共展示了IAuthSession.ConvertTo方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnAuthenticated
public override void OnAuthenticated(IServiceBase authService, IAuthSession session, IAuthTokens tokens, Dictionary<string, string> authInfo)
{
base.OnAuthenticated(authService, session, tokens, authInfo);
//Populate all matching fields from this session to your own custom User table
var user = session.ConvertTo<User>();
user.Id = int.Parse(session.UserAuthId);
user.GravatarImageUrl64 = !session.Email.IsNullOrEmpty()
? CreateGravatarUrl(session.Email, 64)
: null;
foreach (var authToken in session.ProviderOAuthAccess)
{
if (authToken.Provider == FacebookAuthProvider.Name)
{
user.FacebookName = authToken.DisplayName;
user.FacebookFirstName = authToken.FirstName;
user.FacebookLastName = authToken.LastName;
user.FacebookEmail = authToken.Email;
}
else if (authToken.Provider == TwitterAuthProvider.Name)
{
user.TwitterName = user.DisplayName = authToken.UserName;
}
else if (authToken.Provider == GoogleOpenIdOAuthProvider.Name)
{
user.GoogleUserId = authToken.UserId;
user.GoogleFullName = authToken.FullName;
user.GoogleEmail = authToken.Email;
}
else if (authToken.Provider == YahooOpenIdOAuthProvider.Name)
{
user.YahooUserId = authToken.UserId;
user.YahooFullName = authToken.FullName;
user.YahooEmail = authToken.Email;
}
}
if (AppHost.AppConfig.AdminUserNames.Contains(session.UserAuthName)
&& !session.HasRole(RoleNames.Admin))
{
using (var assignRoles = authService.ResolveService<AssignRolesService>())
{
assignRoles.Post(new AssignRoles {
UserName = session.UserAuthName,
Roles = { RoleNames.Admin }
});
}
}
//Resolve the DbFactory from the IOC and persist the user info
using (var db = authService.TryResolve<IDbConnectionFactory>().Open())
db.Save(user);
}
示例2: SaveUserAuth
public void SaveUserAuth(IAuthSession authSession)
{
var userAuth = !authSession.UserAuthId.IsNullOrEmpty()
? (UserAuth)GetUserAuth(authSession.UserAuthId)
: authSession.ConvertTo<UserAuth>();
if (userAuth.Id == default(int) && !authSession.UserAuthId.IsNullOrEmpty())
userAuth.Id = int.Parse(authSession.UserAuthId);
userAuth.ModifiedDate = DateTime.UtcNow;
if (userAuth.CreatedDate == default(DateTime))
userAuth.CreatedDate = userAuth.ModifiedDate;
mongoDatabase.GetCollection<UserAuth>(UserAuthCol);
SaveUser(userAuth);
}
示例3: SaveUserAuth
public void SaveUserAuth(IAuthSession authSession)
{
using (_session)
{
int idInt = int.Parse(authSession.UserAuthId);
var userAuth = !authSession.UserAuthId.IsNullOrEmpty()
? _session.Load<UserAuth>(idInt)
: authSession.ConvertTo<UserAuth>();
if (userAuth.Id == default(int) && !authSession.UserAuthId.IsNullOrEmpty())
userAuth.Id = idInt;
userAuth.ModifiedDate = DateTime.UtcNow;
if (userAuth.CreatedDate == default(DateTime))
userAuth.CreatedDate = userAuth.ModifiedDate;
_session.Store(userAuth);
_session.SaveChanges();
}
}
示例4: SaveUserAuth
public void SaveUserAuth(IAuthSession authSession)
{
var nhSession = GetCurrentSessionFn(sessionFactory);
var userAuth = !string.IsNullOrEmpty(authSession.UserAuthId)
? nhSession.Load<UserAuthNHibernate>(int.Parse(authSession.UserAuthId))
: authSession.ConvertTo<UserAuth>();
if (userAuth.Id == default(int) && !string.IsNullOrEmpty(authSession.UserAuthId))
userAuth.Id = int.Parse(authSession.UserAuthId);
userAuth.ModifiedDate = userAuth.ModifiedDate;
if (userAuth.CreatedDate == default(DateTime))
userAuth.CreatedDate = userAuth.ModifiedDate;
nhSession.Save(new UserAuthNHibernate(userAuth));
}
示例5: SaveUserAuth
public void SaveUserAuth(IAuthSession authSession)
{
using (var redis = factory.GetClient())
{
var userAuth = !authSession.UserAuthId.IsNullOrEmpty()
? GetUserAuth(redis, authSession.UserAuthId)
: authSession.ConvertTo<UserAuth>();
if (userAuth.Id == default(int) && !authSession.UserAuthId.IsNullOrEmpty())
userAuth.Id = int.Parse(authSession.UserAuthId);
userAuth.ModifiedDate = DateTime.UtcNow;
if (userAuth.CreatedDate == default(DateTime))
userAuth.CreatedDate = userAuth.ModifiedDate;
redis.Store(userAuth);
}
}
示例6: SaveUserAuth
public void SaveUserAuth(IAuthSession authSession)
{
var userAuth = !authSession.UserAuthId.IsNullOrEmpty()
? Session.Load<UserAuthPersistenceDto>(int.Parse(authSession.UserAuthId))
: authSession.ConvertTo<UserAuth>();
if (userAuth.Id == default(int) && !authSession.UserAuthId.IsNullOrEmpty())
userAuth.Id = int.Parse(authSession.UserAuthId);
userAuth.ModifiedDate = userAuth.ModifiedDate;
if (userAuth.CreatedDate == default(DateTime))
userAuth.CreatedDate = userAuth.ModifiedDate;
Session.Save(new UserAuthPersistenceDto(userAuth));
}
示例7: SaveUserAuth
public void SaveUserAuth(IAuthSession authSession)
{
using (var db = dbFactory.Open())
{
var userAuth = !authSession.UserAuthId.IsNullOrEmpty()
? db.GetByIdOrDefault<UserAuth>(authSession.UserAuthId)
: authSession.ConvertTo<UserAuth>();
if (userAuth.Id == default(int) && !authSession.UserAuthId.IsNullOrEmpty())
userAuth.Id = int.Parse(authSession.UserAuthId);
userAuth.ModifiedDate = DateTime.UtcNow;
if (userAuth.CreatedDate == default(DateTime))
userAuth.CreatedDate = userAuth.ModifiedDate;
db.Save(userAuth);
};
}
示例8: SaveUserAuth
/// <summary>
/// Save the UserAuth from the session.
/// </summary>
/// <param name="authSession">The auth session.</param>
public void SaveUserAuth(IAuthSession authSession)
{
var userAuth =
!string.IsNullOrEmpty(authSession.UserAuthId)
? this.GetUserAuth(authSession.UserAuthId)
: authSession.ConvertTo<LightSpeed.UserAuth>();
if (userAuth.Id == default(int)
&& !string.IsNullOrEmpty(authSession.UserAuthId))
{
userAuth.Id = int.Parse(authSession.UserAuthId);
}
this.SaveUserAuth(userAuth);
}
开发者ID:hhandoko,项目名称:ServiceStack.Authentication.LightSpeed,代码行数:19,代码来源:LightSpeedUserAuthRepository.cs