我怎样才能在ServiceStack更新用户数据表单会话? [英] How can I update user data form session in ServiceStack?

查看:153
本文介绍了我怎样才能在ServiceStack更新用户数据表单会话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很简单的问题:我有一个会话对象在我的服务:

Very simple question: I have a session object in my Service:

var session = this.GetSession(); //IAuthSession
   if (!session.IsAuthenticated)

我可以修改会话类的基础上传递到服务的参数的一些值(例如权限);然后,我要拯救他们。
怎么样?

I can modify some values in the session class (e.g. Permissions) based on the parameters passed to the service; then I want to save them. How?

这样做的直接的方法:创建一个对象USERAUTH与来自IAuthSession所有字段popolate它,得到的IDbConnectionFactory,保存它。

The direct way of doing it: create a UserAuth object, popolate it with all the fields from IAuthSession, get the IDbConnectionFactory, save it.

当然有更快更好的方式,但我没能找到它!

Surely there is a faster and better way, but I was not able to find it!

更一般地,我怎么能IAuthSession ANF USERAUTH之间切换?即,给定一个IAuthSession对象,我怎么能获得USERAUTH对象,修改它,并坚持修改?

More generally, how can I switch between IAuthSession anf UserAuth? I.e., given a IAuthSession object, how can I obtain a UserAuth object, modify it, and persist the modifications?

我已经阅读了这个问题上如何添加元数据到用户的登录信息的事,但至今下落不明。

I have read this question on how to append metadata to a user login info, but something is still missing.

一旦你添加你需要什么,你怎么保存呢? (我怀疑你刚才添加的元数据都会话和USERAUTH,然后使用IDbConnectionFactory保存后,必须有一个更好的办法!)

Once you have added what you need, how do you save it? (I doubt you just add the metadata to both session and UserAuth, and then you use IDbConnectionFactory to save the latter; there must be a better way!)

推荐答案

老问题,但值得回答。

Old question but worth answering.

UserAuthRepository 使用应该有 UpdateUserAuth 方法,可以调用保存的实施 USERAUTH 修改

The UserAuthRepository being used should have an implementation of the UpdateUserAuth method that can be called to save the UserAuth changes

UpdateUserAuth(UserAuth existingUser, UserAuth newUser, string password)

另一种更简单的方法是只叫 RegisterService 使用 PUT 将更新现有注册用户给你

Another easier way would be to just call the RegisterService using PUT which will update the existing registered user for you.

/// <summary>
/// Update an existing registraiton
/// </summary>
public object Put(Register request)
{
   return Post(request);
}

该服务调用将类似于这样:

The service call would be something similar to this:

using (var authService = base.ResolveService<RegisterService>())
{
   var authResponse = authService.Put(
       new Register {
           UserName = session.UserName ?? session.Email,
           Email = session.Email,
           etc...
       });

   if (authResponse is IHttpError)
     throw (Exception)authResponse;
}

这篇关于我怎样才能在ServiceStack更新用户数据表单会话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆