解析:一个用户可以创建另一个用户吗? [英] Parse: Can a user create another user?

查看:88
本文介绍了解析:一个用户可以创建另一个用户吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了这篇文章:一个用户可以在以下位置创建另一个用户吗?解析?但我认为它不能回答问题.

I have read this post: Can a user create another user in parse? but I don't think it answers the question.

所以我将以这种方式提出问题:

So I will put the question this way:

我是老师.我班上有20个孩子.我想将它们添加到我的应用程序中,因为我可以通过该应用程序将他们的成绩输入Parse,供父母查看.我当前正在使用我的应用程序创建一个新用户,成功创建一个新用户后,我成为该用户.我不想成为那个用户,我只想创建他并将自己留在应用程序中.那怎么可能?我的应用程序当前正在使用Parse Javascript SDK.即将推出...它将在使用Swift的iPhone上实现.

I am a teacher. I have 20 kids in my class. I want to add them to my application because I this app allows me to enter their grades into Parse for their parents to see. I am currently using my application to create a new user and after I successfully creating a new user, I become that user. I don't want to become that user, I just want to create him and remain myself in the app. How is that possible? My app is currently using the Parse Javascript SDK. And coming soon...it will be on iPhone using Swift.

这是我正在使用的简单代码:

Here is the simple code I am using:

var user = new Parse.User();
user.set("username", t_username.value);
user.set("password", t_password.value);
user.signUp(null, {
    success: function (user) {
        alert('New user created!');
        //but now i am that user??!?!

        },
    error: function (user, error) {
    // Show the error message somewhere and let the user try again.
    alert("Error: " + error.code + " " + error.message);
    }
});

推荐答案

感谢所有发布回复的人.您启发了我搜索会话令牌和user.become函数.

Thanks to all who posted responses. You inspired me to search for session tokens and user.become function.

此代码可以解决问题!

var user = new Parse.User();
user.set("username", t_username.value);
user.set("password", t_password.value);

var sessionToken = Parse.User.current().get("sessionToken");
//at this point the "teacher" is the current user
//i save this user session for use later
user.signUp(null, {
    success: function (user) {
        //right now i have successfully signed up a new "student" and am actually logged in as that student
        Parse.User.become(sessionToken).then(function (user) {
        // The current user is now set back to the teacher.
        // Continue doing what you want
        }, function (error) {
            // The token could not be validated.
            alert('error');
        });
     },
        error: function (user, error) {
        // Show the error message somewhere and let the user try again                    alert("Error: " + error.code + " " + error.message);
            }
     });
  }

这篇关于解析:一个用户可以创建另一个用户吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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