本文整理汇总了C#中IErrorService.MissingParameters方法的典型用法代码示例。如果您正苦于以下问题:C# IErrorService.MissingParameters方法的具体用法?C# IErrorService.MissingParameters怎么用?C# IErrorService.MissingParameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IErrorService
的用法示例。
在下文中一共展示了IErrorService.MissingParameters方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApplicationModule
public ApplicationModule(IApplicationService applicationService, IErrorService error)
: base("/application")
{
Post["/register"] = _ =>
{
if (Params.AreMissing("SingleUseToken", "Name")) return error.MissingParameters(Response);
if (!Params.SingleUseToken.IsGuid()) return error.InvalidParameters(Response);
if (!applicationService.AuthoriseSingleUseToken(Params.SingleUseToken)) return error.PermissionDenied(Response);
var application = applicationService.Register(Params.Name);
return (application == null) ? error.InvalidParameters(Response) : Response.AsJson(new { ApplicationId = application.Id });
};
Post["/transfer"] = _ =>
{
if (Params.AreMissing("SingleUseToken", "Name", "Id")) return error.MissingParameters(Response);
if (!Params.Id.IsGuid() || !Params.SingleUseToken.IsGuid()) return error.InvalidParameters(Response);
if (!applicationService.AuthoriseSingleUseToken(Params.SingleUseToken)) return error.PermissionDenied(Response);
var application = applicationService.Transfer(Params.Name, Params.Id);
return (application == null) ? error.InvalidParameters(Response) : Response.AsJson(new { ApplicationId = application.Id });
};
}
示例2: RootModule
public RootModule(IErrorService error)
{
Get["/"] = _ =>
{
return "ThumbsUp Security Service is Running";
};
Get["/error/{code}"] = url =>
{
if (Params.AreMissing("Code")) return error.MissingParameters(Response);
return Response.AsJson(new { ErrorCode = Params.Code, ErrorMessage = error.Decode(Params.Code)});
};
}
示例3: UserModule
public UserModule(IUserService userService, IErrorService error, IPasswordService passwordService, IUserCacheService userCacheService)
: base("/user")
{
Post["/create"] = _ =>
{
if (Params.AreMissing("UserName", "Email")) return error.MissingParameters(Response);
if (userService.GetUserByName(Params.UserName)!=null) return error.UserNameTaken(Response);
if (!Params.Email.IsEmail()) return error.InvalidParameters(Response);
var password = userService.CreateUser(Params.UserName, Params.Email);
return (string.IsNullOrWhiteSpace(password)) ? error.InvalidParameters(Response) : Response.AsJson(new { Password = password });
};
Post["/validate"] = _ =>
{
if (Params.AreMissing("UserName", "Password")) return error.MissingParameters(Response);
var user = userService.GetUserByName(Params.UserName);
if (user == null || !passwordService.IsPasswordValid(user, Params.Password)) return error.NoUserForCredentials(Response);
var key = userCacheService.Add(user);
return (key == null) ? error.InvalidParameters(Response) : Response.AsJson(new { ThumbKey = key });
};
Post["/get"] = _ =>
{
if (Params.AreMissing("ThumbKey")) return error.MissingParameters(Response);
if (!Params.ThumbKey.IsGuid()) return error.InvalidParameters(Response);
var user = userCacheService.GetUser(Params.ThumbKey);
return (user == null) ? error.NoUserForThumbkey(Response) : Response.AsJson(new { User = new { Id = user.Id, UserName = user.UserName, Email = user.Email } });
};
Post["/validate/thumbkey"] = _ =>
{
if (Params.AreMissing("ThumbKey")) return error.MissingParameters(Response);
if (!Params.ThumbKey.IsGuid()) return error.InvalidParameters(Response);
var isValid = userCacheService.Validate(Params.ThumbKey);
return !isValid ? error.NoUserForThumbkey(Response) : HttpStatusCode.OK;
};
Post["/validate/name"] = _ =>
{
if (Params.AreMissing("UserName")) return error.MissingParameters(Response);
var isValid = userService.GetUserByName(Params.UserName)==null;
return !isValid ? error.UserNameTaken(Response) : HttpStatusCode.OK;
};
Post["/reset/password"] = _ =>
{
if (Params.AreMissing("UserName", "Password")) return error.MissingParameters(Response);
var user = userService.GetUserByName(Params.UserName);
if (user == null || !passwordService.IsPasswordValid(user, Params.Password)) return error.NoUserForCredentials(Response);
var password = userService.ResetPassword(user);
return (password == null) ? error.InvalidParameters(Response) : Response.AsJson(new { Password = password });
};
Post["/forgot-password/request"] = _ =>
{
if (Params.AreMissing("UserName", "Email")) return error.MissingParameters(Response);
if (!Params.Email.IsEmail()) return error.InvalidParameters(Response);
var user = userService.GetUserByName(Params.UserName);
if (user == null) return error.NoUserForCredentials(Response);
if (user.Email != Params.Email) return error.NoUserForEmail(Response);
var token = userService.ForgotPasswordRequest(user);
return (token == null) ? error.InvalidParameters(Response) : Response.AsJson(new { Token = token });
};
Post["/forgot-password/reset"] = _ =>
{
if (Params.AreMissing("UserName", "Token")) return error.MissingParameters(Response);
if (!Params.Token.IsGuid()) return error.InvalidParameters(Response);
var user = userService.GetUserByName(Params.UserName);
if (user == null || !passwordService.IsForgotPasswordTokenValid(user, Params.Token)) return error.InvalidForgotPasswordToken(Response);
var password = userService.ForgotPasswordReset(user);
return (password == null) ? error.InvalidParameters(Response) : Response.AsJson(new { Password = password });
};
Post["/logout"] = _ =>
{
if (Params.AreMissing("ThumbKey")) return error.MissingParameters(Response);
if (!Params.ThumbKey.IsGuid()) return error.InvalidParameters(Response);
var success = userCacheService.Remove(Params.ThumbKey);
return !success ? error.NoUserForThumbkey(Response) : HttpStatusCode.OK;
};
}