Exemple #1
0
    def post(self, request):
        print(request.POST)

        login = request.POST['email']
        password = request.POST['password']

        if not models.User.objects.filter(login=login, password=password):

            new_user = models.User(login=login, password=password)
            new_user.save()
        else:
            does_exist_login = login
            return render(request, 'index_page.html', {
                'does_exist_login': does_exist_login,
            })

        #нижній рядок взагалі для того щоб коли людина зареєстувалась щоб не приходилось логінитись
        request.session['user_id'] = new_user.id
        # юзер айді то моя придумана назва а new user я витягую з створеного нев юзер з попереднього рядка (назва крапка для переходу по властивості (айді логін пароль

        request.session['name_for_message'] = login
        # name_for_message = request.session.get('name_for_message')

        #сесіями можна користуватись в різних вюхах. я роблю редірект на іншу вюху того мені це требв

        return redirect('/')
Exemple #2
0
def user_by_username(request, username):
    # create user if doesn't exist
    try:
        user = models.User.objects.get(username=username)
    except models.User.DoesNotExist:
        user = models.User(username=username)
        user.save()

    return JsonResponse({"username": user.username, "id": user.pk})
Exemple #3
0
    def put(self, email, postcode):
        # Check availability:
        existed_user = db_session.query(
            models.User).filter_by(email=email).first()
        if existed_user:
            if existed_user.status:
                return dict(result="ok", message="user is already active")
            existed_user.status = True
            db_session.add(existed_user)
            db_session.commit()
            taks.emailAgent.delay(
                email,
                "Coronavirus Map Account Reactivation",
                f"""
                        You requested to reactivate your notification account,
                        please click on the link bellow to reactivate your account.

                            {c.PROTOCOL}://{c.DOMAIN}:{c.PORT}/api/v1/activate/{existed_user.token}

                        If you are not requested this action, please ignore this email.

                        --
                        Be Safe.
                    """,
            )
            return dict(result="ok",
                        message="User already registered. Reactivated again")
        else:
            # Check postcode availabitity:
            postcode_obj = (db_session.query(
                models.Postcode).filter_by(postcode=postcode).first())
            if not postcode_obj:
                return dict(result="error", message="Postcode is not valid")
            else:
                new_user = models.User(email,
                                       postcode=postcode_obj,
                                       status=True)
                db_session.add(new_user)
                db_session.commit()
                tasks.emailAgent.delay(
                    email,
                    "Welcome to Coronavirus Map Notifications",
                    f"""
                            Welcome. To complete your registeration process, please
                            click on the link bellow:

                            {c.PROTOCOL}://{c.DOMAIN}:{c.PORT}/api/v1/activate/{new_user.token}

                            If you are not requested this action, please ignore this email.

                            --
                            Be Safe.

                        """,
                )
                return dict(result="ok",
                            message="User registered successfully")
Exemple #4
0
def register(conn, dic):
    name = dic.get("name")
    pwd = dic.get("pwd")
    pwd_md = comment.get_md5(pwd)
    flag = comment.check_user_name(name)
    if flag:
        dic_back = {"flag": 0, "msg": "用户已经存在!"}
    else:
        user_obj = models.User(name=name, password=pwd_md, is_vip=0, is_locked=0, user_type=dic.get("user_type"),
                               register_time=comment.get_time())
        user_obj.save()
        dic_back = {"flag": 1, "msg": "注册成功!"}
    comment.service_send(conn, dic_back)
Exemple #5
0
def register(dic, conn):
    name = dic.get("name")
    pwd = dic.get("pwd")
    if not comment.check_name(name):
        dic_back = {"flag": 1, "msg": "注册成功!"}
        comment.service_send(conn, dic_back)
        a = models.User(name=name,
                        password=pwd,
                        is_vip=0,
                        is_locked=0,
                        user_type=dic.get("user_type"),
                        register_time=time.strftime("%Y-%m-%d %H:%M:%S"))
        a.save()
    else:
        dic_back = {"flag": 0, "msg": "用户已经存在!"}
        comment.service_send(conn, dic_back)
Exemple #6
0
    def post(self, request):

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

        if not models.User.objects.filter(login=login, password=password):
            new_user = models.User(login=login, password=password)
            new_user.save()

        else:
            login_exist = login
            print(login_exist)
            return HttpResponse(
                f' user {login_exist} already exist. try sign_in')

        request.session['user_id'] = new_user.id

        return redirect('/')
def register(conn, dic):
    name = dic.get("name")
    pwd = dic.get("pwd")
    user_type = dic.get("user_type")
    flag = comment.check_user(name)
    if flag:
        dic1 = {"flag": 0, "msg": "用户已存在!"}
        comment.service_send(conn, dic1)
        return
    password = comment.get_md5(pwd)
    register_time = time.strftime("%Y-%m-%d %H:%M:%S")
    user_obj = models.User(name=name,
                           password=password,
                           is_vip=0,
                           is_locked=0,
                           user_type=user_type,
                           register_time=register_time)
    user_obj.save()
    dic1 = {"flag": 1, "msg": "注册成功!"}
    comment.service_send(conn, dic1)
Exemple #8
0
    def post(self, request):

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

        if not models.User.objects.filter(login=login, password=password):
            new_user = models.User(login=login, password=password)
            new_user.save()

        else:
            login_exist = login

            return render(request, 'i.html', {
                'login_exist': login_exist
            })

        request.session['user_id'] = new_user.id




        return redirect('/')
 def create(self, validated_data):
     user = models.User(**validated_data)
     user.save()
     return user
Exemple #10
0
    def post(self):
        # Create an organization and assign the user as an administrator
        org_data = self.get_secure_cookie('company_data')

        if not org_data:
            self.redirect('/organization/create')

        org_data = json.loads(org_data)

        admin_email = self.get_argument('admin_email', None)
        admin_email_confirm = self.get_argument('admin_email_confirm', None)

        if admin_email != admin_email_confirm:
            return self.render(
                "auth/admin_create.html",
                errors=
                "The email and the confirmation does not match, please fix it."
            )

        admin_avatar = self.request.files['admin_avatar']
        if admin_avatar is not None:
            fileinfo = admin_avatar[0]
            fname = fileinfo['filename']
            extn = os.path.splitext(fname)[1]
            cname = str(uuid.uuid4()) + extn
            admin_avatar = cname
            fh = open(__UPLOADS__ + 'user_avatars/' + cname, 'w')
            fh.write(fileinfo['body'])

        admin_name = self.get_argument('admin_name', None)
        admin_last_name = self.get_argument('admin_last_name', None)
        admin_user = self.get_argument('admin_user', None)
        admin_password = self.get_argument('admin_password', None)

        try:
            # We have gathered all the data needed, so now we create everything.
            org = models.Organization(name=org_data['org_name'],
                                      address=org_data['org_address'],
                                      unique_domain=org_data['org_subdomain'],
                                      lat_lang=','.join(
                                          org_data['latittude_long']),
                                      logo=org_data['org_logo'])

            session = self.get_session()
            session.add(org)

            usr = models.User(name=admin_name,
                              last_name=admin_last_name,
                              email=admin_email,
                              password=admin_password,
                              username=admin_user,
                              avatar=admin_avatar,
                              organization_user=org)

            session.add(usr)
            session.commit()
            self.redirect('/')
        except ValueError:
            return self.render(
                "auth/org_create.html",
                errors=
                "There was an error when trying to create this organization, please try again in "
                "a moment")
Exemple #11
0
                #调配公共库客户归属
                # __user_id = _user_id_1 or _user_id_2
                # try:
                #     user = models.User.query.get(__user_id)
                #     if user.user_type == 2 and not user.assign_operator_id:
                #         user.assign_operator_id = op_id
                #         user.assign_time = datetime.now()
                #         user.assign_retain_time = 0
                #         db.session.commit()
                #         assign_user_nums += 1
                # except:
                #     pass
                continue

            user = models.User()
            user.name = name
            user.phone = phone
            #user.gender = gender
            #user.phone2 = phone2
            #user.tel = tel

            user.origin = 99  #user_origin
            user.user_type = 1
            user.assign_operator_id = 4
            user.is_assigned = True
            user.operator_id = 4
            user.assign_time = datetime.now()
            user.assign_retain_time = 0
            # if op_id:
            #     user.assign_operator_id = op_id
Exemple #12
0
def init_database():
    clearup()

    for k, v in global_settings.items():
        en = cm.GlobalSettings()
        en.name = k
        en.value = v
        en.save()

    users = {}
    for i in def_users:
        r = cm.User()
        r.user = i['user']
        r.name = i['name']
        r.passwd = i['passwd']
        r.age = i['age']
        r.email = i['email']
        r.save()

        users[i['id']] = i  # users= {id,user}
        i['delta'] = r  #关联信息到 dbobj

    teams = {}
    for id, user in users.items():
        #user['delta']  指向 dbobj
        for teaminfo in user['teams']:  #依次创建群
            team = cm.UserTeam()
            team.user = user['delta']
            team.name = teaminfo['name']
            team.save()
            teaminfo['owner_id'] = id
            teaminfo['delta'] = team
            teams[teaminfo['id']] = teaminfo

            #rel = cm.TeamRelation()
            #rel.user = team.user
            #rel.team = team
            #rel.save()
            #rel = cm.UserRelation()
            #rel.user = user['delta']
            #rel.friend = user['delta']
            #rel.team = team
            #rel.save()  #将本人加入自己的群内

    for id, user in users.items():
        for teamid in user['in_teams']:
            team = teams[teamid]
            userid = team['owner_id']
            owner_of_team = users[userid]
            rel = cm.UserRelation()
            rel.user = owner_of_team['delta']
            rel.friend = user['delta']
            #rel.team = team['delta']
            rel.save()

            rel = cm.UserRelation()
            rel.user = user['delta']
            rel.friend = owner_of_team['delta']
            rel.save()

            rel = cm.TeamRelation()
            rel.user = user['delta']
            rel.team = team['delta']
            rel.save()
Exemple #13
0
def user_create(*, email: str, username: str) -> models.User:
    user = models.User(email=email, username=username)
    user.save()
    return user