vgquotes/Src/VideoGameQuotes.Web/Services/FormsAuthenticationService.cs
tmont 99cb4defbe * login/logout
* change administration password
2011-02-17 20:55:47 +00:00

34 lines
1.0 KiB
C#

using System.Web.Security;
using Portoa.Persistence;
using Portoa.Web.Security;
using Portoa.Web.Session;
using VideoGameQuotes.Api.Persistence;
namespace VideoGameQuotes.Web.Services {
public class FormsAuthenticationService : IAuthenticationService {
private readonly IUserRepository userRepository;
private readonly ISessionStore sessionStore;
public FormsAuthenticationService(IUserRepository userRepository, ISessionStore sessionStore) {
this.userRepository = userRepository;
this.sessionStore = sessionStore;
}
[UnitOfWork]
public void Login(string username) {
FormsAuthentication.SetAuthCookie(username, true);
sessionStore["user"] = userRepository.FindByUsername(username);
}
public void Logout() {
FormsAuthentication.SignOut();
sessionStore["user"] = null;
}
[UnitOfWork]
public bool IsValid(string username, string password) {
var user = userRepository.FindByUsername(username);
return user != null && user.VerifyPassword(password);
}
}
}