本文整理汇总了C#中ServiceClient.GetUserByEmail方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceClient.GetUserByEmail方法的具体用法?C# ServiceClient.GetUserByEmail怎么用?C# ServiceClient.GetUserByEmail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ServiceClient
的用法示例。
在下文中一共展示了ServiceClient.GetUserByEmail方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LogIn
/// <summary>Attempts to log in as the User that identifies itself with the given email and password.</summary>
/// <param name="email">The email that identifies the user.</param>
/// <param name="password">The password that authorizes the user.</param>
public static void LogIn(string email, string password)
{
if (_sessionUser != null)
throw new NotLoggedOutException();
using (var client = new ServiceClient())
{
var temp = client.GetUserByEmail(email);
if (temp == null)
throw new NoSuchUserException();
if (!temp.Password.Equals(password))
throw new IncorrectPasswordException();
_sessionUser = temp;
}
}
示例2: UserExists
/// <summary>Used to check if there exists a User with a certain email.</summary>
/// <param name="email">The email of the User in question.</param>
/// <returns>True if there exists such a User, false if not.</returns>
private static bool UserExists(string email)
{
using (var client = new ServiceClient())
{
try
{
return client.GetUserByEmail(email).Email.Equals(email);
}
catch (Exception)
{
return false;
}
}
}
示例3: GetUserByEmail
/// <summary>Look up a User by its email address.</summary>
/// <param name="email">The email of the User to be returned.</param>
/// <returns>The User whose Email property matches the given email.</returns>
public static User GetUserByEmail(string email)
{
if (_sessionUser == null)
throw new NotLoggedInException();
if (_sessionUser.Type != UserType.admin && !_sessionUser.Email.Equals(email))
throw new InsufficientRightsException();
if(!UserExists(email))
throw new ObjectNotFoundException();
using (var client = new ServiceClient())
{
return client.GetUserByEmail(email);
}
}