コード例 #1
0
    def post(self, request):
        username = request.data['username']
        password = request.data['password']
        print(username, password)
        ### Dev mock user
        message = '请检查填写的内容!'
        uinfo = API_tools.check_user(username, password)
        if "错误" in uinfo:
            message = "用户名或密码错误!"
            print(message)
            response = {
                "status": "error",
                "type": "account",
                "currentAuthority": "guest"
            }
            return Response(data=response)
        else:
            UID = int(uinfo["payload"]["userInfo"]["userId"])
            DUser = models.User.objects.filter(id=UID)
            print("UID,len", UID, DUser)
            #mntpath = str(username)+"_mnt",
            if len(DUser) == 0:
                new_user = models.User.objects.create_user(
                    username=username,
                    tocken=API_tools.get_tocken(username, password),
                    password=password,
                    first_name=password,
                    id=UID)
                new_user.save()
            else:
                DUser[0].username = username
                DUser[0].set_password(password)
                DUser[0].first_name = password
                DUser[0].tocken = API_tools.get_tocken(username, password)
                DUser[0].save()
            user = auth.authenticate(username=username,
                                     password=password)  # 验证是否存在用户
            print(user)
            if (user):
                print("login!!!!!!!!!!!!!!!!!!")
                auth.login(request, user)
                print(request.session)

        response = {
            "status": "ok",
            "type": "account",
            "currentAuthority": "user",
        }
        return Response(data=response)
コード例 #2
0
def refresh_train_job(user):
    '''
    Args:
        user: 用户实例
    '''
    # 以本地数据库的信息为主
    un=user.username
    pa=user.first_name
    token=API_tools.get_tocken(un,pa)
    job_list=models.customize_job.objects.all()
    for rec in job_list:
        # print("JOB: ", rec.jobid)
        info=API_tools.get_jobinfo(rec.job_id,token,un,pa)
        if info['code'] == 'S000': # 存在该任务
            job=info['payload']
            rec.state = job["jobStatus"]["state"]
            timeStamp2 = int(job['jobStatus']["completedTime"])
            if timeStamp2 == 0: continue
            rec.completed_at = datetime.datetime.fromtimestamp(
                timeStamp2/1000 )
            rec.save()            
        else:
            rec=models.customize_job.objects.get(id=rec.id)
            rec.delete()