コード例 #1
0
ファイル: index.py プロジェクト: cfxcheer/myobject
def regupdate(request):
    #判断两次密码是否一致
    pwd = request.POST['passwd']
    repwd = request.POST['repasswd']
    name = request.POST['username']
    if Users.objects.filter(username=name):
        content = {'info': '用户名已被注册'}
    else:
        if repwd != pwd:
            content = {"info": "两次密码不相同,请重新输入!"}
            return render(request, "web/register.html", content)
        try:
            gb = Users()
            gb.username = request.POST['username']
            import hashlib
            m = hashlib.md5()
            m.update(bytes(request.POST['passwd'], encoding="utf8"))
            gb.password = m.hexdigest()
            gb.email = request.POST['email']
            gb.phone = request.POST['phone']
            gb.addtime = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
            gb.state = 1
            gb.save()
            content = {"info": "注册成功!可以登录了"}
            return render(request, "web/register.html", content)
        except:
            content = {"info": "注册失败!"}
    return render(request, "web/register.html", content)
コード例 #2
0
ファイル: helpers.py プロジェクト: BZWGolem/ColdSeats
def create_user(username, password, token=None):
    user_query = Users.select().where(Users.username == username)
    
    if user_query.exists():
        print('TEST')
        return {'status': 'Username: "******" exists'.format(username)}
    else:
        pass_hash = bcrypt.hash(password)
        Users.insert(username=username, pass_hash=pass_hash, token=token).execute()
        return {'Username: "******" created'.format(username)}
コード例 #3
0
def doregister(request):
    '''会员注册'''
    try:
        ob = Users()
        ob.username = request.POST['username']
        password = request.POST["password"]
        repassword = request.POST["repassword"]
        if password != repassword:
            context = {'info': '两次输入的密码不一致!'}
            raise Exception
        user = Users.objects.filter(username=username)
        if user:
            context = {'info': '当前用户名已经存在!'}
            raise Exception
        #获取密码并md5
        import hashlib
        m = hashlib.md5()
        m.update(bytes(request.POST['password'], encoding="utf8"))
        ob.password = m.hexdigest()
        ob.state = 1
        ob.addtime = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        ob.save()
        request.session['vipuser'] = ob.toDict()
        context = {"info": "注册成功!"}
    except Exception as err:
        print(err)
    return render(request, "web/register.html", context)
コード例 #4
0
ファイル: helpers.py プロジェクト: BZWGolem/ColdSeats
def validate_user(username, password):
    try:
        user = Users.select().where(Users.username == username).get()
    except Users.DoesNotExist:
        return {'verify': False}

    if bcrypt.verify(password, user.pass_hash):
        token = uuid.uuid4()
        Users.update(token=token).where(Users.id_user == user).execute()
        return {'status': True, 'token': str(token)}
    return {'verify': False}
コード例 #5
0
def desk_confirm(nfc_id, token):
    try:
        user = Users.select().where(Users.token == token).get()
    except Users.DoesNotExist:
        return {'status': 'Wrong user token', 'code': 'E012'}
    date = datetime.datetime.now().strftime("%Y%m%d")
    desk = Desks.select().where(Desks.nfc_id == nfc_id).get()

    # check if reservation for user exists
    try:
        reserve = (Reservations.select()
                               .where(Reservations.id_desk == desk)
                               .where(Reservations.timestamp == date)
                               .get())

        if reserve.id_user == user:
            (Reservations.update(status='TAKEN')
                         .where(Reservations.id_desk == desk)
                         .where(Reservations.timestamp == date)
                         .where(Reservations.id_user == user)
                         .execute())
        else:
            return {'status': 'Cannot take', 'id_desk': desk.id_desk, 'code': 'E011'}
    except Reservations.DoesNotExist:
        Reservations.create(id_user=user,
                            id_desk=desk,
                            timestamp=date,
                            status='TAKEN')
    
    return {'status': 'Taken', 'id_desk': desk.id_desk}
コード例 #6
0
def get_floor_data(building_name, number, date, token):
    try:
        user = Users.select().where(Users.token == token).get()
    except Users.DoesNotExist:
        return {'status': 'Wrong user token', 'code': 'E012'}

    if date == '':
        need_date = datetime.datetime.now().strftime("%Y%m%d")
    else:
        need_date = date
    try:
        building = (Buildings.select().where(
            Buildings.name == building_name).get())
    except Buildings.DoesNotExist:
        return {'status': 'No Building found', 'code': 'E005'}

    try:
        floor = (Floors.select().where(
            Floors.id_building == building.id_building).where(
                Floors.number == number).get())
    except Floors.DoesNotExist:
        return {'status': 'No Floor found', 'code': 'E005'}

    try:
        desk = (Desks.select().where(
            Desks.id_building == building.id_building).where(
                Desks.number == number))
        desk_list = [{
            'id_desk': desk_data.id_desk,
            'status': 'FREE'
        } for desk_data in desk]
    except Floors.DoesNotExist:
        desk_list = []

    # get reservation data
    for index, desk in enumerate(desk_list):
        reservation_query = (Reservations.select().where(
            Reservations.id_desk == desk['id_desk']).where(
                Reservations.timestamp == need_date))
        if reservation_query.exists():
            reserv = reservation_query.get()
            desk_list[index]['status'] = reserv.status
            if reserv.id_user == user:
                if reserv.status == 'RESERVED':
                    desk_list[index]['status'] = 'MY_RESERVED'
                elif reserv.status == 'TAKEN':
                    desk_list[index]['status'] = 'MY_TAKEN'

    row_str_list = floor.shape.split(';')
    column_str_list = row_str_list[0].split(',')

    return_shape = floor.shape.replace(';', ',')

    return {
        'shape': return_shape,
        'desks_id': desk_list,
        'width': len(column_str_list),
        'height': len(row_str_list)
    }
コード例 #7
0
ファイル: index.py プロジェクト: sogoodnow/python-study
def doregister(request):
    # 获取注册信息
    username = request.POST.get('username')
    password = request.POST.get('password')
    repassword = request.POST.get('repassword')
    # 判断两次密码输入是否一致
    if password != repassword:
        context = {"info": "密码输入不一致"}
        return render(request, "web/register.html", context)
    else:
        try:
            # 判断用户是否存在
            count = Users.objects.filter(phone=username).count()
            print(count)
            if count > 0:
                context = {"info": "用户已存在"}
                return render(request, "web/register.html", context)
            else:
                # 添加数据进入模型
                user = Users()
                user.phone = username
                user.username = username
                # 密码处理
                import hashlib
                m = hashlib.md5()
                m.update(bytes(password, encoding='utf8'))
                user.password = m.hexdigest()
                user.save()
                # 完成后跳转至登录页面
                context = {"info": "注册完成,请登录"}
                return render(request, "web/login.html", context)
        except Exception as e:
            context = {"info": "注册失败" + e}
            return render(request, "web/register.html", context)
コード例 #8
0
def doregister(request):
	'''执行会员注册操作'''
	#获取并判断用户名是否为空
	username = request.POST['username']
	if len(username) == 0:
		context = {"info":"用户名不能为空!"}
		return render(request,"web/register.html",context)
	#获取并判断两次输入的密码是否一致
	password = request.POST['password']
	repassword = request.POST['repassword']
	if password != repassword:
		context = {"info":"两次输入的密码不一致!"}
		return render(request,"web/register.html",context)
	try:
		#实例化对象
		ob = Users()
		#用ob进行封装
		ob.username = request.POST['username']
		#获取密码并进行MD5加密操作
		import hashlib
		m = hashlib.md5()
		m.update(bytes(request.POST['password'],encoding="utf8"))
		ob.password = m.hexdigest()
		ob.state = 1
		ob.save()
		context = {"info":"注册成功,请点击登录!"}
	except Exception as err:
		print(err)
		context = {"info":"用户名已存在,请重新输入!"}
	return render(request,"web/register.html",context)
コード例 #9
0
ファイル: index.py プロジェクト: zhangjunjie02/phone
def doregister(request):
    '''执行注册'''
    try:
        ob = Users()
        ob.username = request.POST['username']
        ob.name = request.POST['name']
        import hashlib
        m = hashlib.md5()
        m.update(bytes(request.POST['password'], encoding="utf8"))
        ob.password = m.hexdigest()
        ob.state = 1
        ob.create_at = datetime.now()
        ob.update_at = datetime.now()
        ob.save()
    except Exception as err:
        print(err)

    return render(request, "myadmin/login.html")
コード例 #10
0
def insert(request):
    '''执行添加信息'''
    try:
        ob = Users()
        ob.username = request.POST['username']
        ob.name = request.POST['name']
        import hashlib
        m = hashlib.md5()
        m.update(bytes(request.POST['password'], encoding="utf8"))
        ob.password = m.hexdigest()
        ob.state = 1
        ob.create_at = datetime.now()
        ob.update_at = datetime.now()
        ob.save()
        context = {"info": "添加成功"}

    except Exception as err:

        print(err)
        context = {"info": "添加失败"}
    return render(request, 'myadmin/info.html', context)
コード例 #11
0
ファイル: index.py プロジェクト: lvz5069au/week7_hw
def doregister(request):
    '''会员执行注册'''
    try:
        #判断是否重复用户名
        user = Users.objects.filter(username=request.POST['username'])
        if len(user) > 0:
            context = {'info': '此用户名已存在!'}
            return render(request, "web/register.html", context)
        else:
            #判断两次密码是否正确
            password = request.POST['password']
            repassword = request.POST['repassword']
            if password != repassword:
                context = {'info': '两次密码不一样!'}
                return render(request, "web/register.html", context)
            #新建账号
            ob = Users()
            import hashlib
            m = hashlib.md5()
            m.update(bytes(request.POST['password'], encoding="utf8"))
            ob.password = m.hexdigest()
            ob.username = request.POST['username']
            ob.save()
            context = {'info': '注册成功!'}
            return render(request, "web/login.html", context)
    except Exception as err:
        print(err)
        context = {'info': '注册失败!'}
    return render(request, "web/register.html", context)
コード例 #12
0
def insert(request):
    '''执行会员信息添加'''
    try:
        ob = Users()
        ob.username = request.POST['account']
        #获取密码并md5
        import hashlib
        m = hashlib.md5()
        m.update(bytes(request.POST['password'],encoding="utf8"))
        ob.password = m.hexdigest()
        ob.phone = request.POST['account']
        ob.state = 1
        ob.addtime = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        ob.save()
        context={"info":"注册成功!"}
    except Exception as err:
        print(err)
        context={"info":"注册失败"}
    return render(request,"web/info.html",context)
コード例 #13
0
def insert(request):
    try:
        ob = Users()
        ob.sid = request.POST['username']
        ob.state = request.POST['state']

        if ob.state == '':
            ob.state = 0

        ob.password = request.POST['password']

        ob.save()

        sqllist = []
        #根据用户id创建一个数据库
        sqllist.append(f'create database {ob.sid};')

        #给数据库创建一个用户
        if int(ob.state) == 0:  #学生
            sqllist.append("create user {} identified by '{}';".format(
                ob.sid, request.POST['password']))
            sqllist.append("grant select on pub.* to {};".format(ob.sid))
            sqllist.append(
                "grant drop, create, select, insert, update, delete on {}.* to {};"
                .format(ob.sid, ob.sid))
            sqllist.append("flush privileges;")

        else:
            sqllist.append("create user {} identified by '{}';".format(
                ob.sid, request.POST['password']))
            sqllist.append(
                "grant drop, create, select, insert, update, delete on testdb.* to {};"
                .format(ob.sid))
            sqllist.append("grant all on pub.* to {};".format(ob.sid))
            sqllist.append("grant all on {}.* to {};".format(ob.sid, ob.sid))
            sqllist.append("flush privileges;")
        print(sqllist)

        excute_sql(sqllist)

        context = {'info': '添加成功!'}
    except Exception as err:
        print(err)
        context = {'info': '添加失败!'}

    return render(request, "myadmin/info.html", context)
コード例 #14
0
def get_desk_data(id_desk, date, token):
    if token:
        try:
            user = Users.select().where(Users.token == token).get()
        except Users.DoesNotExist:
            return {'status': 'Wrong user token', 'code': 'E012'}

    if date == '':
        need_date = datetime.datetime.now().strftime("%Y%m%d")
    else:
        need_date = date

    try:
        desk = (Desks.select(Desks, Floors)
                     .join(Floors, on=((Desks.number == Floors.number) & (Desks.id_building == Floors.id_building)))
                     .where(Desks.id_desk == id_desk).get())
    except Desks.DoesNotExist:
        return {'status': 'No Desk found', 'code': 'E005'}
    
    desk_cursor = database.execute_sql("""SELECT id_desk, d.number, b.name FROM desks d
                         JOIN floors f ON d.number = f.number AND d.id_building = f.id_building
                         JOIN buildings b ON f.id_building = b.id_building
                         WHERE d.id_desk = %s LIMIT %s OFFSET %s""", [id_desk, 1, 0])
    desk = desk_cursor.fetchall()[0]
  
    try:
        reservation = (Reservations.select()
                                   .where(Reservations.id_desk == desk[0])
                                   .where(Reservations.timestamp == need_date)
                                   .get())
        if token:
            if reservation.id_user == user:
                reservation_dict = {'status': "MY_{}".format(reservation.status), 'username': reservation.id_user.username}
            else:
                reservation_dict = {'status': reservation.status, 'username': reservation.id_user.username}
        else:
            reservation_dict = {'status': reservation.status, 'username': reservation.id_user.username}
    except Reservations.DoesNotExist:
        reservation_dict = {'status': 'FREE', 'username': ''}

    return {'building_name': desk[2],
            'floor_name': desk[1],
            'id_desk': desk[0],
            'date': need_date,
            'status': reservation_dict['status'],
            'username':  reservation_dict['username']}
コード例 #15
0
ファイル: index.py プロジェクト: Zhangjifa/Django_mall
def doreg(request):
    try:
        ob = Users()
        ob.username = request.POST['username']
        # 获取密码并md5
        import hashlib
        m = hashlib.md5()
        m.update(bytes(request.POST['password'], encoding="utf8"))
        ob.password = m.hexdigest()
        ob.addtime = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        ob.save()
        context = {'info': '注册成功, 请登陆!'}
    except Exception as err:
        print(err)
        context = {'info': '注册失败,请重试!'}

    return render(request, "web/register.html", context)
コード例 #16
0
def find_me(token):
    try:
        user = Users.select().where(Users.token == token).get()
    except Users.DoesNotExist:
        return {'status': 'Wrong user token', 'code': 'E012'}

    date = datetime.datetime.now().strftime("%Y%m%d")

    try:
        reservation = (Reservations.select().where(
            Reservations.id_user == user).where(
                Reservations.timestamp == date).where(
                    (Reservations.status == 'TAKEN')
                    | (Reservations.status == 'RESERVED')).get())
        building_name = reservation.id_desk.number.id_building.name
        number = reservation.id_desk.number.number
        return {'building_name': building_name, 'number': number}
    except Reservations.DoesNotExist:
        return {'status': 'No current desk reserved or took', 'code': 'E011'}
コード例 #17
0
def vipadd(request):
    ''' 写入注册信息界面 '''
    try:
        ob = Users()
        ob.username = request.POST['username']
        ob.password = request.POST['password']
        ob.repassword = request.POST['repassword']
        if ob.password != ob.repassword:
            context = {"info": "两次密码不符"}
        else:
            #获取密码并md5
            import hashlib
            m = hashlib.md5()
            m.update(bytes(ob.password, encoding="utf8"))
            ob.password = m.hexdigest()  #调用hexdigest方法对密码进行加密
            ob.save()
            context = {'info': '注册成功,请登陆!'}
            return render(request, 'web/login.html', context)
    except Exception as err:
        context = {"info": '注册失败,该账户已存在!'}
    return render(request, 'web/vip/register.html', context)
コード例 #18
0
def desk_reserve(id_desk, date, token):
    try:
        user = Users.select().where(Users.token == token).get()
    except Users.DoesNotExist:
        return {'status': 'Wrong user token', 'code': 'E012'}

    # check if reservation exists
    reserve = (Reservations.select()
                           .where(Reservations.id_desk == id_desk)
                           .where(Reservations.timestamp == date)
                           .where(Reservations.id_user != user))
    if reserve.exists():
        return {'status': 'Cannot reserve', 'id_desk': id_desk, 'code': 'E010'}
    
    Reservations.get_or_create(id_user=user,
                        id_desk=id_desk,
                        timestamp=date,
                        status='RESERVED')
    return {'status': 'Reserved', 'id_desk': id_desk}
コード例 #19
0
def doregister(request):
    try:
        ob = Users()
        ob.username = request.POST['username']
        if request.POST['password'] == request.POST['repassword']:
            import hashlib
            m = hashlib.md5()
            m.update(bytes(request.POST['password'], encoding="utf8"))
            ob.password = m.hexdigest()
            ob.state = 1
            ob.addtime = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
            ob.save()
            context = {"info": "添加成功!请重新登录"}
            return render(request, 'web/login.html', context)
        else:
            context = {'info': '两次输入密码不一致!'}
            return render(request, 'web/register.html', context)

    except Exception as err:
        print(err)
        context = {'info': '注册账号错误!'}
    return render(request, 'web/register.html', context)
コード例 #20
0
def insereguser(request):
    try:
        ulist = Users()
        ulist.username = request.POST['txt_name']
        #获取密码并md5
        import hashlib
        m = hashlib.md5()
        m.update(bytes(request.POST['txt_pwd1'], encoding="utf8"))
        ulist.password = m.hexdigest()
        ulist.save()
        context = {'info': "注册成功,请重新登录!"}
        return render(request, "myweb/vipuser/reguser.html", context)
    except Exception as info:
        context = {'info': "注册成功,请重新登录!"}
        return render(request, "myweb/vipuser/reguser.html", context)
コード例 #21
0
def delete_reservation(token, date):
    if date == '':
        need_date = datetime.datetime.now().strftime("%Y%m%d")
    else:
        need_date = date

    try:
        user = Users.select().where(Users.token == token).get()
    except Users.DoesNotExist:
        return {'status': 'Wrong user token', 'code': 'E012'}

    reservation_query = (Reservations.select()
                                     .where(Reservations.id_user == user)
                                     .where((Reservations.status == 'TAKEN') | (Reservations.status == 'RESERVED'))
                                     .where(Reservations.timestamp == need_date))
    if reservation_query.exists():
        for reservation in reservation_query:
            Reservations.delete().where(Reservations.id_reservation == reservation).execute()
        return {'status': 'Deleted reservation', 'date': date, 'user': user.username}
    else:
        return {'status': 'No reservation', 'date': date, 'user': user.username, 'code': 'W001'}
コード例 #22
0
def insert(request):
	#执行注册
	user=Users()
	verifycode = request.session['verifycode']
	code = request.POST['code'] 
	if verifycode != code:
		context = {'info':'验证码错误!'}
		return render(request,"./web/login.html",context)
	user.username=request.POST['username']
	password1=request.POST.get('password1')
	password2=request.POST.get('password2')
	if password1 != password2:
		context={'info':'两次密码不一致!'}
		return render(request,'./web/login.html',context)
	else:
		#如果注册成功,则直接跳转到首页.
		import hashlib
		m = hashlib.md5() 
		m.update(bytes(password2,encoding="utf8"))
		user.password=m.hexdigest()
		user.save()
		request.session['webuser']=user.toDict()
		return render(request,'./web/index.html')
コード例 #23
0
ファイル: index.py プロジェクト: RenShixu/djangoMall
def doregister(request):
    '''
    执行注册
    :param request:
    :return:
    '''
    # 判断用户名是否已注册
    try:
        username = request.POST["username"]
        user = Users.objects.filter(username=username)
        if user:
            context = {"info": "该账号已注册"}
            return render(request, "web/useregister.html", context)

        user = Users()
        user.username = username
        user.name = request.POST["name"]
        user.password = encryptionUtil.getencodepassword(
            request.POST["password"])
        user.sex = request.POST["sex"]
        user.code = request.POST["code"]
        user.address = request.POST["address"]
        user.state = 1
        user.phone = request.POST["phone"]
        user.email = request.POST["email"]

        user.save()
        request.session["vipuser"] = user.toDict()
        return redirect(reverse("index"))
    except Exception as err:
        print(err)
        context = {"info": "注册信息异常"}
    return render(request, 'web/useregister.html', context)
コード例 #24
0
def insert(request):
    '''执行添加'''
    try:
        ob = Users()
        ob.username = request.POST['username']
        ob.name = request.POST['name']
        #获取密码并md5
        import hashlib
        m = hashlib.md5()
        m.update(bytes(request.POST['password'], encoding="utf8"))
        ob.password = m.hexdigest()
        ob.sex = request.POST['sex']
        ob.address = request.POST['address']
        ob.code = request.POST['code']
        ob.phone = request.POST['phone']
        ob.email = request.POST['email']
        ob.state = 1
        ob.addtime = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        ob.save()
        context = {"info": "添加成功!"}
    except Exception as err:
        print(err)
        context = {"info": "添加失败"}
    return render(request, "myadmin/info.html", context)
コード例 #25
0
def insert(request):
    """执行添加"""
    try:
        ob = Users()  # 实例化Users模型
        ob.username = request.POST['registerUsername']

        # 密码md5加密
        import hashlib
        m = hashlib.md5()
        m.update(bytes(request.POST['registerPassword'], encoding='utf-8'))
        ob.password = m.hexdigest()

        ob.sex = request.POST['gender']
        ob.email = request.POST['registerEmail']
        ob.phone = request.POST['registerPhone']
        ob.state = 1
        ob.addtime = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        ob.save()  # 将数据存储至数据库
        return redirect('/users')
    except Exception as err:
        print(err)
        context = {'Info': 'Addition Failed', 'Detail': err}
        return render(request, 'backstage/info.html', context)
コード例 #26
0
ファイル: users.py プロジェクト: MartinJhon/Shopping
def insert(request):
    '''添加数据'''
    try:
        ob = Users()
        ob.username = request.POST['username']
        ob.name = request.POST['name']

        ob.password = request.POST['password']
        ob.repassword = request.POST['repassword']
        if ob.password != ob.repassword:
            context = {"info": "两次密码不符"}
        else:
            # 获取密码并md5
            import hashlib
            m = hashlib.md5()
            m.update(bytes(ob.password, encoding="utf8"))
            ob.password = m.hexdigest()  # 调用hexdigest方法对密码进行加密
            ob.sex = request.POST['sex']
            ob.address = request.POST['address']
            ob.code = request.POST['code']
            ob.phone = request.POST['phone']
            ob.email = request.POST['email']
            ob.state = 1
            ob.addtime = datetime.now().strftime("%Y-%m-%d %H:%M:%S")  # 格式化时间
            ob.save()
            context = {'info': '添加成功'}
    except Exception as err:
        context = {"info": '添加失败'}
    return render(request, 'myadmin/info.html', context)
コード例 #27
0
def insert(request):
    try:
        user = Users()
        user.username = request.POST['username']
        user.name = request.POST['name']

        import hashlib
        md5 = hashlib.md5()  #md5对象,md5不能反解,但是加密是固定的,就是关系是一一对应,所以有缺陷,可以被对撞出来
        md5.update(bytes(request.POST['password'],
                         encoding='utf-8'))  #要对哪个字符串进行加密,就放这里
        user.password = md5.hexdigest()  #拿到加密字符串
        print(f"md5加密之后的结果:{user.password}")

        user.sex = request.POST['sex']
        user.address = request.POST['address']
        user.code = request.POST['code']
        user.phone = request.POST['phone']
        user.email = request.POST['email']
        user.state = '1'
        user.addtime = datetime.now().strftime("%Y-%m-%d %H:%H:%S")
        user.save()
        print(user.addtime)
        context = {'info': '会员添加成功!'}
    except Exception as err:
        context = {'info': '会员添加失败!'}
        print(f"添加失败的原因是:{err}")
    return render(request, './myadmin/users/info.html', context)
コード例 #28
0
ファイル: users.py プロジェクト: wangqcl/monitor
def insert(request):
    try:
        ob = Users()
        ob.username = request.POST['username']
        ob.name = request.POST['name']
        passw = request.POST['password']
        dj_ps = make_password(passw, None, 'pbkdf2_sha256')  #加密
        ob.password = dj_ps
        ob.phone = request.POST['phone']
        ob.email = request.POST['email']
        ob.state = 1
        ob.addtime = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        ob.save()
        context = {'info': '保存成功!'}
    except Exception as err:
        print(err)
        context = {'info': '保存失败!'}
    return render(request, 'myadmin/info.html', context)
コード例 #29
0
ファイル: users.py プロジェクト: chargerKong/django
def insert(httpRequest):
	'''执行添加'''
	try:
		mod = Users()
		mod.username = httpRequest.POST.get('username',None)
		mod.name = httpRequest.POST.get('name',None)
		# mod.password = httpRequest.POST.get('password',None)
		
		#获取密码并md5
		
		m = hashlib.md5() 
		m.update(bytes(httpRequest.POST['password'],encoding="utf8"))
		mod.password = m.hexdigest()

		mod.sex = httpRequest.POST.get('sex',None)
		mod.address = httpRequest.POST.get('address',None)
		mod.phone = httpRequest.POST.get('phone',None)
		mod.email = httpRequest.POST.get('email',None)
		mod.state = 1
		mod.code = httpRequest.POST.get('code',None)
		mod.save()
		data = {"info":'添加成功'}

	except Exception as e:
		print(e)
		data = {"info":'账号已被注册添加!'}
		return render(httpRequest,'myadmin/info.html',data)

	return render(httpRequest,'myadmin/info.html',data)
コード例 #30
0
def insert(request):
    '''执行添加'''
    #根据账号获取登录者信息
    user = Users.objects.get(id=request.session['volunteers']['id'])

    try:
        ob = Users()
        ob.username = request.POST['username']
        ob.name = request.POST['name']
        #获取密码并md5
        import hashlib
        m = hashlib.md5()
        m.update(bytes(request.POST['password'], encoding="utf8"))
        ob.password = m.hexdigest()
        ob.sex = request.POST['sex']
        ob.student_id = request.POST['student_id']
        ob.phone = request.POST['phone']
        ob.email = request.POST['email']
        ob.state = 1
        ob.addtime = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        ob.save()
        context = {"info": "添加成功!", "state": user.state}
    except Exception as err:
        print(err)
        context = {"info": "添加失败", "state": user.state}
    return render(request, "myadmin/info.html", context)