def import_user(): '''导入亿脉通所有用户''' users=User.objects.all() from django.db import connection client=Client(MockRequest()) for user in users: print 'import %s ' % user.username username=user.username id= client.user_register(username,'123456',user.email) if int(id)>0: rs=connection.cursor() rs.execute('update auth_user set reference_id=%s where id=%s',[id,user.id]) rs.close()
def import_user_by_name(username,password): '''导入亿脉通所有用户''' user=User.objects.get(username=username) from django.db import connection client=Client(MockRequest()) print 'import %s ' % username s= client.user_register(username,password,user.email) print s return if int(id)>0: try: rs=connection.cursor() rs.execute('update auth_user set reference_id=%s where id=%s',[id,user.id]) rs.close() except: transaction.rollback() raise else: transaction.commit()
def test(request): if request.method=='POST': username=request.REQUEST.get('username','') password=request.REQUEST.get('password','') try: user=User.objects.get(username=username) except User.DoesNotExist: return HttpResponse(u'用户不存在') email=user.email from it.ucenter.client import Client client=Client(request) result=client.user_register(username,password,email) if not (result in REGISTER_STATUS): try: result=int(result) if result>0: try: from django.db import connection rs=connection.cursor() rs.execute('update auth_user set reference_id=%s where username=%s',[result,username]) rs.close() except: transaction.rollback() raise else: transaction.commit() return HttpResponse(u'注册成功 返回 uid %s ' % result) return HttpResponse(u'未知错误,返回代码 %s' % result) except: raise return HttpResponse(u'未知错误,返回 %s' % result) else: return HttpResponse(REGISTER_STATUS[result]) else: return HttpResponse(''' <html> <head> <title>手动同步账号到bbs</title> </head> <body> <form action='.' method='POST'> <table> <tr><td colspan='2'>输入您在亿脉通中的账号和密码</td></tr> <tr> <td>用户名</td><td><input type='text' name='username'></td> </tr> <tr> <td>口令</td> <td> <input type='password' name='password'> </td> </tr> </table> <center> <input type='submit' value='test register'/> </center> </form> </body> </html> ''')