Beispiel #1
0
    def save(self):
        userInput = self.getInput()  
        # 只有admin才能新增用户
        if not self.isAdmin():
            return self.error(msg = '权限不足!', url=self.makeUrl('/admin/users/list'))

        thumbnail_id = int(userInput['thumbnail']) if userInput.has_key('thumbnail') else 0
        if thumbnail_id:
            thumbnail_data = Images.get(Images.id == thumbnail_id).thumbnail
        else:
            import base64
            from imaging import imaging
            thumbnail_data = base64.b64encode(buffer(imaging.default_thumbnail()))

        try:
            Users.create(
                cellphone = userInput['cellphone'],
                email = userInput['email'],
                name = userInput['name'],
                password = hashlib.md5(userInput['passwd']).hexdigest(),
                avatur = thumbnail_data,
                gender = int(userInput['gender']),
                description = userInput['desc'],
                role = int(userInput['role'])
            )
        except Exception, e:
            return self.error(msg = '会员保存失败: %s' % e, url=self.makeUrl('/admin/users/list'))
Beispiel #2
0
 def post(self):
     args = self.parser.parse_args()
     if args:
         u = Users.create(**args)
         if u:
             return u.__dict__
     return {}, 404
Beispiel #3
0
    def __init__(self):
        db.connect()
        self.version = None
        self.admin = None
        self.sys_category = None
        self.default_thumbnail = None
        self.sys_image = None

        if not Version.table_exists():
            tables = [
                Version,
                Categories,
                Products,
                News,
                Notifications,
                Images,
                Orders,
                OrderDetails,
                Users,   
                Contacts,
                Accountings,
                AccountIncommings,
                AccountOutgoings,
                Questions,
                Answers,
                Albums
            ]
        
            db.create_tables(tables)

            self.version=Version.create(description=open('VERSION').read())
            self.default_thumbnail = base64.b64encode(buffer(imaging.default_thumbnail()))
  
 
            self.sys_category = Categories.create(
                            name = '系统预置分类',
                            description = '预置的初始父类!',
                         )

            self.sys_image = Images.create(
                            description = '预置的系统图片!',
                            thumbnail = self.default_thumbnail,
                            uuid = 'default'
                         )

            self.admin = Users.create(
                            name = 'admin',
                            cellphone = '13912345678',
                            email = '*****@*****.**',
                            password = '******',
                            gender = 0,
                            avatur = self.sys_image,
                            description = '系统管理员',
                            weixin= '0',
                            address= 'sv',
                         )
Beispiel #4
0
    def signup(self):
        inputs = self.get_input()
        try:
            log.info('signup:' + str(inputs))
            cellphone = inputs.get('cellphone')
            smscode = inputs.get('smscode')
            tuser = Users.get(Users.cellphone == cellphone)
            if tuser:
                return self.error()
        except Exception as e:
            log.error('execus signup %s' % traceback.format_exc())
            return self.error()

        try:
            pwd = md5(inputs['password']).hexdigest()

            if not leancloud.Apis().verify_sms_code(cellphone, smscode):
                return self.error()
            signup_token = gen_token()
            created_time = datetime.datetime.now()

            Users.create(
                cellphone=cellphone,
                name=cellphone,
                password=pwd,
                gender=0,
                role=2,
                description=self.htmlunquote(''),
                address="住址",
                token=signup_token,
                token_created_time=created_time,
                birthday="1970-5-12",
                avatur=Images.get(Images.id == 1).thumbnail,
            )
            return self.success()
        except Exception as e:
            log.error('execus signup%s' % traceback.format_exc())
            return self.error()
Beispiel #5
0
    def save(self):
        userInput = self.getInput()  
        # 只有admin才能新增用户
        if not self.isAdmin():
            return self.error(msg = '权限不足!', url=self.makeUrl('/admin/users/list'))

        thumbnail_id = int(userInput['thumbnail']) if userInput.has_key('thumbnail') else 0

        try:
            Users.create(
                cellphone = userInput['cellphone'],
                email = userInput['email'],
                name = userInput['name'],
                password = hashlib.md5(userInput['password']).hexdigest(),
                avatur = thumbnail_id,
                gender = int(userInput['gender']),
                description = userInput['desc'],
                job = userInput['job'],
                weixin = userInput['weixin'],
                address = userInput['address']
            )
        except Exception, e:
            return self.error(msg = '会员保存失败: %s' % e, url=self.makeUrl('/admin/users/list'))
Beispiel #6
0
def register_page():
    form = RegisterForm()
    if request.method == "POST":
        if form.validate_on_submit():
            username = form.data["username"]
            user = get_user(username)
            if user is None:
                parser = reqparse.RequestParser()
                parser.add_argument('username', type=str)
                parser.add_argument('password', type=str)
                parser.add_argument('is_admin', type=bool)
                parser.add_argument('active', type=bool)
                args = parser.parse_args()
                u = Users.create(**args)
                print(u)
                print(type(u))
                flash("You have signed up!")
                next_page = request.args.get("next", url_for("home_page"))
                return redirect(next_page)
            flash("Already exist username.")
    return render_template("register.html", form=form)
Beispiel #7
0
def init_db():
    """
    Initializing database and creating necessary files for user profile images view.
    :return: HTTP Response
    """

    if not os.path.exists(os.path.join(os.getcwd(), 'static', 'media')):
        os.makedirs(os.path.join(os.getcwd(), 'static', 'media'))
        os.mkdir(
            os.path.join(os.getcwd(), 'static', 'media', 'profile_pictures'))

    Team.create()
    Users.create()

    if len(Users.get(is_admin=True)) == 0:

        tables = [
            Team, Contest, Users, Problems, Tag, ProblemTag, Message,
            Clarification, Notification, Discussion, Submissions, Input,
            ContestUser, UsersUpvote, UsersDownvote
        ]

        for table in tables[::-1]:
            table.drop()
        for table in tables:
            table.create()

        # Teams and Users
        bumbles = Team(team_name='HumbleBumbles')
        bumbles.save()
        burakbugrul = Users(username='******',
                            email='*****@*****.**',
                            password='******',
                            is_admin=True,
                            team_id=bumbles.team_id)
        burakbugrul.save()

        packers = Team(team_name='HackerPackers')
        packers.save()
        hackergirl = Users(username='******',
                           email='*****@*****.**',
                           password='******',
                           is_admin=True,
                           team_id=packers.team_id)
        hackergirl.save()
        pax = Users(username='******',
                    email='*****@*****.**',
                    password='******',
                    is_admin=True,
                    team_id=packers.team_id)
        pax.save()

        # Contests
        online = Contest(contest_name='online',
                         start_time=datetime.now(),
                         end_time=datetime.now() + timedelta(days=1000))
        online.save()

        past = Contest(contest_name='past',
                       start_time=datetime.now() - timedelta(days=1000),
                       end_time=datetime.now() - timedelta(days=1))
        past.save()

        future = Contest(contest_name='future',
                         start_time=datetime.now() + timedelta(days=500),
                         end_time=datetime.now() + timedelta(days=1000))
        future.save()

        # Problems
        easy = Problems(problem_name='Easy',
                        statement='This problem is easy',
                        contest_id=online.contest_id,
                        max_score=100)
        easy.save()

        moderate = Problems(problem_name='Moderate',
                            statement='This problem is moderate',
                            contest_id=online.contest_id,
                            max_score=100)
        moderate.save()

        hard = Problems(problem_name='Hard',
                        statement='This problem is hard',
                        contest_id=online.contest_id,
                        max_score=100)
        hard.save()

        past_prob = Problems(problem_name='Old',
                             statement='This problem is old',
                             contest_id=past.contest_id,
                             max_score=100)
        past_prob.save()

        new_prob = Problems(problem_name='New',
                            statement='This problem is new',
                            contest_id=future.contest_id,
                            max_score=100)
        new_prob.save()

        # Tags

        dynamic = Tag(tag_name='Dynamic')
        dynamic.save()

        graph = Tag(tag_name='Graph')
        graph.save()

        greedy = Tag(tag_name='Greedy')
        greedy.save()

        games = Tag(tag_name='Game-Theory')
        games.save()

        ProblemTag.save_tags_to_problem(easy, [greedy])
        ProblemTag.save_tags_to_problem(moderate, [dynamic, games])
        ProblemTag.save_tags_to_problem(hard, [dynamic, graph, greedy])

        # Inputs

        inp = Input(problem_id=easy.problem_id,
                    testcase='input',
                    expected_output='output')
        inp.save()

        inp = Input(problem_id=easy.problem_id,
                    testcase='input2',
                    expected_output='output2')
        inp.save()

        inp = Input(problem_id=moderate.problem_id,
                    testcase='input moderate',
                    expected_output='output moderate')
        inp.save()

        inp = Input(problem_id=hard.problem_id,
                    testcase='input hard',
                    expected_output='output hard')
        inp.save()

    return redirect(url_for('core.home'))