创建用户后如何防止自动登录 [英] How to prevent auto login after create user

查看:109
本文介绍了创建用户后如何防止自动登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Meteor

当我这样创建用户时:

Accounts.createUser({username: username, password : password}, function(err){
          if (err) {
            // Inform the user that account creation failed
            console.log("Register Fail!") 
            console.log(err)
          } else {
               console.log("Register Success!")
            // Account has been created and the user has logged
          }    
  });

帐户已创建,用户已登录.

Account has been created and the user has logged.

例如,我以管理员身份登录,我想为某人创建一个帐户,但是我不想在创建帐户后注销.

for instance, I log in as an administrator and I want to create a account for somebody,but I don't want to log out after create account.

如何防止创建用户后自动登录?

How to prevent auto login after create user ?

我找到了 accouts-password 软件包的源代码:

I find source code of accouts-password packages:

48-63行:

// Attempt to log in as a new user.
Accounts.createUser = function (options, callback) {
  options = _.clone(options); // we'll be modifying options

  if (!options.password)
    throw new Error("Must set options.password");
  var verifier = Meteor._srp.generateVerifier(options.password);
  // strip old password, replacing with the verifier object
  delete options.password;
  options.srp = verifier;

  Accounts.callLoginMethod({
    methodName: 'createUser',
    methodArguments: [options],
    userCallback: callback
  });
};

我应该修改源代码来解决此问题吗?

Should I modify the source code to solve this problem?

感谢您的帮助.

推荐答案

您正在尝试使用客户端帐户管理来执行一项并非专门为该任务设计的任务.

You're trying to use client side accounts management to perform a task it hasn't been designed for.

客户端帐户软件包的目的是专门允许新用户创建其帐户并希望立即登录.

Client side accounts package purpose is to specifically allow new users to create their account and expect to be logged in immediately.

您必须记住,某些功能可以以不同的行为在客户端和/或服务器上运行,Accounts.createUser docs指定:在客户端上,此功能以成功创建的新用户身份登录."

You have to remember that certain functions can be ran on the client and/or on the server with different behaviors, Accounts.createUser docs specifies that : "On the client, this function logs in as the newly created user on successful completion."

相反,在服务器上,它返回新创建的用户ID." (不会与客户端上当前登录的用户混淆).

On the contrary, "On the server, it returns the newly created user id." (it doesn't mess with the currently logged in user on the client).

为了解决您的问题,您应该编写一种服务器端方法来创建一个新用户,并在正确填写自己设计的用户创建表单后,能够从客户端管理面板中调用它.

In order to solve your problem, you should write a server side method creating a new user and be able to call it from your client side admin panel, after filling correctly a user creation form of your own design.

这篇关于创建用户后如何防止自动登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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