本文整理汇总了C#中IJabbrRepository.GetUserById方法的典型用法代码示例。如果您正苦于以下问题:C# IJabbrRepository.GetUserById方法的具体用法?C# IJabbrRepository.GetUserById怎么用?C# IJabbrRepository.GetUserById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IJabbrRepository
的用法示例。
在下文中一共展示了IJabbrRepository.GetUserById方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetLoginViewModel
private LoginViewModel GetLoginViewModel(IApplicationSettings applicationSettings,
IJabbrRepository repository,
IAuthenticationService authService)
{
ChatUser user = null;
if (Context.CurrentUser != null)
{
user = repository.GetUserById(Context.CurrentUser.UserName);
}
var viewModel = new LoginViewModel(applicationSettings.AuthenticationMode,
authService.Providers,
user != null ? user.Identities : null);
return viewModel;
}
示例2: EnsureClientConnected
// This is an uber hack to make sure the db is in sync with SignalR
private void EnsureClientConnected(ILogger logger, IJabbrRepository repo, ITrackingConnection connection)
{
var contextField = connection.GetType().GetField("_context",
BindingFlags.NonPublic | BindingFlags.Instance);
if (contextField == null)
{
return;
}
var context = contextField.GetValue(connection) as HostContext;
if (context == null)
{
return;
}
string connectionData = context.Request.QueryString["connectionData"];
if (String.IsNullOrEmpty(connectionData))
{
return;
}
var hubs = JsonConvert.DeserializeObject<HubConnectionData[]>(connectionData);
if (hubs.Length != 1)
{
return;
}
// We only care about the chat hub
if (!hubs[0].Name.Equals("chat", StringComparison.OrdinalIgnoreCase))
{
return;
}
logger.Log("Connection {0} exists but isn't tracked.", connection.ConnectionId);
string userId = context.Request.User.GetUserId();
ChatUser user = repo.GetUserById(userId);
if (user == null)
{
logger.Log("Unable to find user with id {0}", userId);
return;
}
var client = new ChatClient
{
Id = connection.ConnectionId,
User = user,
UserAgent = context.Request.Headers["User-Agent"],
LastActivity = DateTimeOffset.UtcNow,
LastClientActivity = user.LastActivity
};
repo.Add(client);
repo.CommitChanges();
}
示例3: AccountModule
public AccountModule(IApplicationSettings applicationSettings,
IAuthenticationTokenService authenticationTokenService,
IMembershipService membershipService,
IJabbrRepository repository,
IAuthenticationService authService,
IChatNotificationService notificationService)
: base("/account")
{
Get["/"] = _ =>
{
if (Context.CurrentUser == null)
{
return HttpStatusCode.Forbidden;
}
ChatUser user = repository.GetUserById(Context.CurrentUser.UserName);
return GetProfileView(authService, user);
};
Get["/login"] = _ =>
{
if (Context.CurrentUser != null)
{
return Response.AsRedirect("~/");
}
return View["login", GetLoginViewModel(applicationSettings, repository, authService)];
};
Post["/login"] = param =>
{
if (Context.CurrentUser != null)
{
return Response.AsRedirect("~/");
}
string username = Request.Form.username;
string password = Request.Form.password;
if (String.IsNullOrEmpty(username))
{
this.AddValidationError("username", "Name is required");
}
if (String.IsNullOrEmpty(password))
{
this.AddValidationError("password", "Password is required");
}
try
{
if (ModelValidationResult.IsValid)
{
ChatUser user = membershipService.AuthenticateUser(username, password);
return this.CompleteLogin(authenticationTokenService, user);
}
else
{
return View["login", GetLoginViewModel(applicationSettings, repository, authService)];
}
}
catch
{
this.AddValidationError("_FORM", "Login failed. Check your username/password.");
return View["login", GetLoginViewModel(applicationSettings, repository, authService)];
}
};
Post["/logout"] = _ =>
{
if (Context.CurrentUser == null)
{
return HttpStatusCode.Forbidden;
}
var response = Response.AsJson(new { success = true });
response.AddCookie(new NancyCookie(Constants.UserTokenCookie, null)
{
Expires = DateTime.Now.AddDays(-1)
});
return response;
};
Get["/register"] = _ =>
{
if (Context.CurrentUser != null)
{
return Response.AsRedirect("~/");
}
return View["register"];
};
Post["/create"] = _ =>
{
if (Context.CurrentUser != null)
{
//.........这里部分代码省略.........
示例4: GetLoginViewModel
private LoginViewModel GetLoginViewModel(ApplicationSettings applicationSettings,
IJabbrRepository repository,
IAuthenticationService authService)
{
ChatUser user = null;
if (IsAuthenticated)
{
user = repository.GetUserById(Principal.GetUserId());
}
var viewModel = new LoginViewModel(applicationSettings, authService.GetProviders(), user != null ? user.Identities : null);
return viewModel;
}
示例5: AccountModule
public AccountModule(ApplicationSettings applicationSettings,
IMembershipService membershipService,
IJabbrRepository repository,
IAuthenticationService authService,
IChatNotificationService notificationService,
IUserAuthenticator authenticator)
: base("/account")
{
Get["/"] = _ =>
{
if (!IsAuthenticated)
{
return HttpStatusCode.Forbidden;
}
ChatUser user = repository.GetUserById(Principal.GetUserId());
return GetProfileView(authService, user);
};
Get["/login"] = _ =>
{
if (IsAuthenticated)
{
return Response.AsRedirect("~/");
}
return View["login", GetLoginViewModel(applicationSettings, repository, authService)];
};
Post["/login"] = param =>
{
if (IsAuthenticated)
{
return Response.AsRedirect("~/");
}
string username = Request.Form.username;
string password = Request.Form.password;
if (String.IsNullOrEmpty(username))
{
this.AddValidationError("username", "Name is required");
}
if (String.IsNullOrEmpty(password))
{
this.AddValidationError("password", "Password is required");
}
try
{
if (ModelValidationResult.IsValid)
{
IList<Claim> claims;
if (authenticator.TryAuthenticateUser(username, password, out claims))
{
return this.SignIn(claims);
}
}
}
catch
{
// Swallow the exception
}
this.AddValidationError("_FORM", "Login failed. Check your username/password.");
return View["login", GetLoginViewModel(applicationSettings, repository, authService)];
};
Post["/logout"] = _ =>
{
if (!IsAuthenticated)
{
return HttpStatusCode.Forbidden;
}
var response = Response.AsJson(new { success = true });
this.SignOut();
return response;
};
Get["/register"] = _ =>
{
if (IsAuthenticated)
{
return Response.AsRedirect("~/");
}
bool requirePassword = !Principal.Identity.IsAuthenticated;
if (requirePassword &&
!applicationSettings.AllowUserRegistration)
{
return HttpStatusCode.NotFound;
}
//.........这里部分代码省略.........
示例6: NotificationsModule
public NotificationsModule(IJabbrRepository repository,
IChatService chatService,
IChatNotificationService notificationService)
: base("/notifications")
{
Get["/"] = _ =>
{
if (!IsAuthenticated)
{
return Response.AsRedirect(String.Format("~/account/login?returnUrl={0}", HttpUtility.UrlEncode(Request.Path)));
}
var request = this.Bind<NotificationRequestModel>();
ChatUser user = repository.GetUserById(Principal.GetUserId());
int unreadCount = repository.GetUnreadNotificationsCount(user);
IPagedList<NotificationViewModel> notifications = GetNotifications(repository, user, all: request.All, page: request.Page, roomName: request.Room);
var viewModel = new NotificationsViewModel
{
ShowAll = request.All,
UnreadCount = unreadCount,
Notifications = notifications,
DebugMode = (bool)Context.Items["_debugMode"],
};
return View["index", viewModel];
};
Post["/markasread"] = _ =>
{
if (!IsAuthenticated)
{
return HttpStatusCode.Forbidden;
}
int notificationId = Request.Form.notificationId;
Notification notification = repository.GetNotificationById(notificationId);
if (notification == null)
{
return HttpStatusCode.NotFound;
}
ChatUser user = repository.GetUserById(Principal.GetUserId());
if (notification.UserKey != user.Key)
{
return HttpStatusCode.Forbidden;
}
notification.Read = true;
repository.CommitChanges();
notificationService.MessageReadStateChanged(user, notification.Message, notification);
UpdateUnreadCountInChat(repository, notificationService, user);
var response = Response.AsJson(new { success = true });
return response;
};
Post["/markallasread"] = _ =>
{
if (!IsAuthenticated)
{
return HttpStatusCode.Forbidden;
}
ChatUser user = repository.GetUserById(Principal.GetUserId());
IList<Notification> unReadNotifications = repository.GetNotificationsByUser(user).Unread().ToList();
if (!unReadNotifications.Any())
{
return HttpStatusCode.NotFound;
}
foreach (var notification in unReadNotifications)
{
notification.Read = true;
notificationService.MessageReadStateChanged(user, notification.Message, notification);
}
repository.CommitChanges();
UpdateUnreadCountInChat(repository, notificationService, user);
var response = Response.AsJson(new { success = true });
return response;
};
Get["/{key}"] = _ =>
{
if (!IsAuthenticated)
return Response.AsRedirect(String.Format("~/account/login?returnUrl={0}", HttpUtility.UrlEncode(Request.Path)));
var notification = repository.GetNotificationById(_.key);
if (notification == null)
//.........这里部分代码省略.........
示例7: AccountModule
public AccountModule(ApplicationSettings applicationSettings,
IMembershipService membershipService,
IJabbrRepository repository,
IAuthenticationService authService,
IChatNotificationService notificationService,
IUserAuthenticator authenticator,
IEmailService emailService)
: base("/account")
{
Get["/"] = _ =>
{
if (!IsAuthenticated)
{
return HttpStatusCode.Forbidden;
}
ChatUser user = repository.GetUserById(Principal.GetUserId());
return GetProfileView(authService, user);
};
Get["/login"] = _ =>
{
if (IsAuthenticated)
{
return this.AsRedirectQueryStringOrDefault("~/");
}
return View["login", GetLoginViewModel(applicationSettings, repository, authService)];
};
Post["/login"] = param =>
{
if (!HasValidCsrfTokenOrSecHeader)
{
return HttpStatusCode.Forbidden;
}
if (IsAuthenticated)
{
return this.AsRedirectQueryStringOrDefault("~/");
}
string username = Request.Form.username;
string password = Request.Form.password;
if (String.IsNullOrEmpty(username))
{
this.AddValidationError("username", LanguageResources.Authentication_NameRequired);
}
if (String.IsNullOrEmpty(password))
{
this.AddValidationError("password", LanguageResources.Authentication_PassRequired);
}
try
{
if (ModelValidationResult.IsValid)
{
IList<Claim> claims;
if (authenticator.TryAuthenticateUser(username, password, out claims))
{
return this.SignIn(claims);
}
}
}
catch
{
// Swallow the exception
}
this.AddValidationError("_FORM", LanguageResources.Authentication_GenericFailure);
return View["login", GetLoginViewModel(applicationSettings, repository, authService)];
};
Post["/logout"] = _ =>
{
if (!IsAuthenticated)
{
return HttpStatusCode.Forbidden;
}
var response = Response.AsJson(new { success = true });
this.SignOut();
return response;
};
Get["/register"] = _ =>
{
if (IsAuthenticated)
{
return this.AsRedirectQueryStringOrDefault("~/");
}
bool requirePassword = !Principal.Identity.IsAuthenticated;
//.........这里部分代码省略.........