Skip to content

Commit

Permalink
too many queries for auth request
Browse files Browse the repository at this point in the history
  • Loading branch information
angelcolmenares committed Mar 5, 2012
1 parent 9eb4139 commit 06f99eb
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/ServiceStack.ServiceInterface/Auth/AuthProvider.cs
Expand Up @@ -105,10 +105,10 @@ public virtual void OnAuthenticated(IServiceBase authService, IAuthSession sessi
{
authInfo.ForEach((x, y) => tokens.Items[x] = y);
}
SaveUserAuth(authService, userSession, authRepo, tokens);
//SaveUserAuth(authService, userSession, authRepo, tokens);
}

OnSaveUserAuth(authService, session);
//OnSaveUserAuth(authService, session);
authService.SaveSession(session, SessionExpiry);
session.OnAuthenticated(authService, session, tokens, authInfo);
}
Expand Down
@@ -1,3 +1,4 @@
using System.Globalization;
using System.Collections.Generic;
using ServiceStack.Common;
using ServiceStack.Common.Web;
Expand Down Expand Up @@ -42,11 +43,12 @@ public virtual bool TryAuthenticate(IServiceBase authService, string userName, s
}

var session = authService.GetSession();
string useUserName = null;
if (authRepo.TryAuthenticate(userName, password, out useUserName))
UserAuth userAuth = null;
if (authRepo.TryAuthenticate(userName, password, out userAuth))
{
session.PopulateWith(userAuth);
session.IsAuthenticated = true;
session.UserAuthName = userName;
session.UserAuthId = userAuth.Id.ToString(CultureInfo.InvariantCulture);

return true;
}
Expand Down Expand Up @@ -94,4 +96,4 @@ protected object Authenticate(IServiceBase authService, IAuthSession session, st
}

}
}
}
4 changes: 2 additions & 2 deletions src/ServiceStack.ServiceInterface/Auth/IUserAuthRepository.cs
Expand Up @@ -7,7 +7,7 @@ public interface IUserAuthRepository
UserAuth CreateUserAuth(UserAuth newUser, string password);
UserAuth UpdateUserAuth(UserAuth existingUser, UserAuth newUser, string password);
UserAuth GetUserAuthByUserName(string userNameOrEmail);
bool TryAuthenticate(string userName, string password, out string userId);
bool TryAuthenticate(string userName, string password, out UserAuth userAuth);
void LoadUserAuth(IAuthSession session, IOAuthTokens tokens);
UserAuth GetUserAuth(string userAuthId);
void SaveUserAuth(IAuthSession authSession);
Expand All @@ -16,4 +16,4 @@ public interface IUserAuthRepository
UserAuth GetUserAuth(IAuthSession authSession, IOAuthTokens tokens);
string CreateOrMergeAuthSession(IAuthSession authSession, IOAuthTokens tokens);
}
}
}
10 changes: 5 additions & 5 deletions src/ServiceStack.ServiceInterface/Auth/OrmLiteAuthRepository.cs
Expand Up @@ -137,16 +137,16 @@ private static UserAuth GetUserAuthByUserName(IDbCommand dbCmd, string userNameO
return userAuth;
}

public bool TryAuthenticate(string userName, string password, out string userId)
public bool TryAuthenticate(string userName, string password, out UserAuth userAuth)
{
userId = null;
var userAuth = GetUserAuthByUserName(userName);
//userId = null;
userAuth = GetUserAuthByUserName(userName);
if (userAuth == null) return false;

var saltedHash = new SaltedHash();
if (saltedHash.VerifyHashString(password, userAuth.PasswordHash, userAuth.Salt))
{
userId = userAuth.Id.ToString(CultureInfo.InvariantCulture);
//userId = userAuth.Id.ToString(CultureInfo.InvariantCulture);
return true;
}
return false;
Expand Down Expand Up @@ -288,4 +288,4 @@ public void Clear()
});
}
}
}
}
10 changes: 5 additions & 5 deletions src/ServiceStack.ServiceInterface/Auth/RedisAuthRepository.cs
Expand Up @@ -175,16 +175,16 @@ private UserAuth GetUserAuthByUserName(IRedisClientFacade redis, string userName
return userId == null ? null : redis.As<UserAuth>().GetById(userId);
}

public bool TryAuthenticate(string userName, string password, out string userId)
public bool TryAuthenticate(string userName, string password, out UserAuth userAuth)
{
userId = null;
var userAuth = GetUserAuthByUserName(userName);
//userId = null;
userAuth = GetUserAuthByUserName(userName);
if (userAuth == null) return false;

var saltedHash = new SaltedHash();
if (saltedHash.VerifyHashString(password, userAuth.PasswordHash, userAuth.Salt))
{
userId = userAuth.Id.ToString(CultureInfo.InvariantCulture);
//userId = userAuth.Id.ToString(CultureInfo.InvariantCulture);
return true;
}
return false;
Expand Down Expand Up @@ -348,4 +348,4 @@ public void Clear()
}
}

}
}

0 comments on commit 06f99eb

Please sign in to comment.