本文整理匯總了C#中ServiceStack.ServiceInterface.Auth.UserAuth.Set方法的典型用法代碼示例。如果您正苦於以下問題:C# UserAuth.Set方法的具體用法?C# UserAuth.Set怎麽用?C# UserAuth.Set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ServiceStack.ServiceInterface.Auth.UserAuth
的用法示例。
在下文中一共展示了UserAuth.Set方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Post
public static Response<User> Post(this User request,
Factory factory,
IHttpRequest httpRequest)
{
if(request.IsDummyPassword())
throw HttpError.Unauthorized("password no válido");
var authRepo = httpRequest.TryResolve<IUserAuthRepository>();
if(authRepo==null)
throw HttpError.NotFound("AuthRepository NO configurado");
var user= new UserAuth
{
FirstName= request.FirstName,
LastName= request.LastName,
Email= request.Email,
UserName= request.UserName,
DisplayName = request.FirstName +" "+ request.LastName
};
user.Set<UserMeta>( new UserMeta{
Cargo= request.Cargo,
Activo=request.Activo,
ExpiresAt= request.ExpiresAt
});
user = authRepo.CreateUserAuth(user, request.Password);
request.Id= user.Id;
request.SetDummyPassword();
List<User> data = new List<User>();
data.Add(request);
return new Response<User>(){
Data=data
};
}
示例2: CreateUser
public User CreateUser(CreateUser request)
{
var httpRequest = RequestContext.Get<IHttpRequest>();
var authRepo = httpRequest.TryResolve<IUserAuthRepository>();
if(authRepo==null)
throw HttpError.NotFound("AuthRepository NO found");
var user= new UserAuth
{
FirstName= request.FirstName,
LastName= request.LastName,
Email= request.Email,
UserName= request.UserName,
DisplayName = request.FirstName +" "+ request.LastName
};
user.Set<UserMeta>( new UserMeta{
Info= request.Info,
IsActive=request.IsActive,
ExpiresAt= request.ExpiresAt
});
user = authRepo.CreateUserAuth(user, request.Password);
User u = new User();
u.PopulateWith(user);
return u;
}
示例3: Put
public static Response<User> Put(this User request,
Factory factory,
IHttpRequest httpRequest)
{
var userSession = httpRequest.GetSession();
if(!( userSession.HasRole(RoleNames.Admin) ||
userSession.HasPermission("User.update") ))
throw HttpError.Unauthorized("Usuario no autorizado para actualizar");
var authRepo = httpRequest.TryResolve<IUserAuthRepository>();
if(authRepo==null)
throw HttpError.NotFound("AuthRepository NO configurado");
var user= authRepo.GetUserAuth(request.Id.ToString());
if (!(request.Id== int.Parse(userSession.UserAuthId) ||
userSession.HasRole(RoleNames.Admin)) )
throw HttpError.Unauthorized("No puede cambiar los datos de otro usuario");
if(user == default(UserAuth))
throw HttpError.NotFound(
string.Format("Usuario con Id:'{0}' NO encontrado",request.Id));
var newUser= new UserAuth
{
Id= request.Id,
FirstName= request.FirstName,
LastName= request.LastName,
Email= request.Email,
UserName= request.UserName,
DisplayName= request.FirstName+" "+request.LastName,
ModifiedDate= System.DateTime.Now,
};
newUser.Set<UserMeta>( new UserMeta{
Cargo= request.Cargo,
Activo=request.Activo,
ExpiresAt= request.ExpiresAt
});
if(request.Password.IsNullOrEmpty()
|| request.IsDummyPassword()){
factory.Execute(proxy=>{
proxy.Update<UserAuth>(
newUser,
ev=>ev.Where(q=>q.Id==request.Id).
Update(f=> new {
f.UserName, f.FirstName, f.LastName, f.Email, f.Meta,
f.DisplayName,
f.ModifiedDate
}));
});
}
else
user = authRepo.UpdateUserAuth(user, newUser,request.Password);
request.SetDummyPassword();
List<User> data = new List<User>();
data.Add(request);
return new Response<User>(){
Data=data
};
}
示例4: Update
public User Update(UpdateUser request)
{
var httpRequest = RequestContext.Get<IHttpRequest>();
var userSession = httpRequest.GetSession();
if(!( userSession.HasRole(RoleNames.Admin)
|| userSession.HasPermission("User.update")
))
throw HttpError.Unauthorized("Update no allowed");
var authRepo = httpRequest.TryResolve<IUserAuthRepository>();
if(authRepo==null)
throw HttpError.NotFound("AuthRepository NO found");
var user= authRepo.GetUserAuth(request.Id.ToString());
if (!(request.Id== int.Parse(userSession.UserAuthId) ||
userSession.HasRole(RoleNames.Admin)) )
throw HttpError.Unauthorized("Update no allowed (no admin)");
if(user == default(UserAuth))
throw HttpError.NotFound(
string.Format("User Id:'{0}' NO found",request.Id));
var newUser= new UserAuth
{
Id= request.Id,
FirstName= request.FirstName,
LastName= request.LastName,
Email= request.Email,
UserName= request.UserName,
DisplayName= request.FirstName+" "+request.LastName,
ModifiedDate= DateTime.Now,
};
newUser.Set<UserMeta>( new UserMeta{
Info= request.Info,
IsActive=request.IsActive,
ExpiresAt= request.ExpiresAt
});
if(request.Password.IsNullOrEmpty())
{
AuthRepoProxy.Execute(db=>{
db.UpdateOnly(
newUser,
ev=>ev.Where(q=>q.Id==request.Id).
Update(f=> new {
f.UserName, f.FirstName, f.LastName, f.Email, f.Meta,
f.DisplayName,
f.ModifiedDate
}));
});
}
else
{
user = authRepo.UpdateUserAuth(user, newUser,request.Password);
}
User u = new User();
u.PopulateWith(newUser);
return u;
}