예제 #1
0
def edituser(id = None):
    user = UserModel()

    if request.method == "POST":
        user.register(request.form['email'], request.form['password'], request.form['nick'], request.form['role'], id)
        flash('You have successfully update user.')
    return render_template("admin/add-user.html", user=user.getUser(id))
def main():
    user_dict = {}
    files_added = []

    if os.path.isfile('test_files/pro_users_seen.pickle'):
        with open('test_files/pro_users_seen.pickle', 'rb') as f:
            files_added = pickle.load(f)

    if os.path.isfile('test_files/pro_user_dict.pickle'):
        with open('test_files/pro_user_dict.pickle', 'rb') as f:
            user_dict = pickle.load(f)

    for f in glob.iglob('./input_mp4s/2kvids/*'):
        if f in files_added:
            continue

        print(f)
        files_added.append(f)

        athlete = f[:-5] + f[-4:]
        if athlete in user_dict:
            u = user_dict[athlete]
            u.add_sample(f)
        else:
            u = UserModel()
            u.add_sample(f)
            user_dict[athlete] = u

        with open('./test_files/pro_user_dict.pickle', 'wb') as handle:
            pickle.dump(user_dict, handle)

        with open('./test_files/pro_users_seen.pickle', 'wb') as handle:
            pickle.dump(files_added, handle)
예제 #3
0
    def post(self):
        user_json = request.get_json()

        data, error = user_schema.load(user_json, partial=True)

        if error:
            return {'message': REQUEST_NOT_VALID}, HTTPStatus.BAD_REQUEST
        if not data.get('email') or not data.get('password') or not data.get('name'):
            return {'message': REQUEST_NOT_VALID}, HTTPStatus.BAD_REQUEST

        is_exist = UserModel.query.filter_by(email=data.get('email')).first()

        if is_exist != None:
            return {'message': USER_EXISTS}, HTTPStatus.BAD_REQUEST

        user = UserModel(data)
        user.save()
        data = user_schema.dump(user).data

        response = {
            'message': 'success',
            'data': data
        }

        return response, HTTPStatus.CREATED
예제 #4
0
    def post(self):
        data = UserRegister.parser.parse_args()
        if UserModel.find_by_username(data['username']):
             return {"message": "Username exists"}, 400

        user = UserModel(**data)
        user.save_to_db()

        return {"message": "User created successful"}, 201
예제 #5
0
def __user_model__():
    if len(sys.argv) < 4:
        print('Not enough argument..')
        return
    __user_id = int(sys.argv[2])
    __model = sys.argv[3]
    if __model is None or __user_id is None:
        print('Not valid arguments')
        return
    User.get_movies_by_user_id(__user_id, __model)
예제 #6
0
def validateLogin(username,password):
    if (Users.getUser(username) and
        validatePassword(password,Users.getPassword(username))):
        return True
    else:
        return False
        
    
        
        
예제 #7
0
def login():

    if session:
        return redirect("/admin")


    if 'email' in request.form and 'password' in request.form:

        model = UserModel()
        if(model.login(request.form['email'], request.form['password'])):
            return redirect("/admin")
        flash("Error. Either something is missing from filed or user/pass is wrong.")

    return render_template('admin/login.html')
예제 #8
0
파일: service.py 프로젝트: willys7/ERP
def AddUser(user):
    if user == {}:
        raise Exception("Invalid User")
    
    userModel = UserModel()
    
    for key, value in user.items():
        if key == 'user_name':
            userModel.user_name = value
        if key == 'password':
            userModel.password = value
        if key =='rol':
            userModel.rol = value
        if key == 'name':
            userModel.name = value
        if key == 'email':
            userModel.email = value
    
    validate = ValidateUser(userModel)

    if validate:
        rol, token = AddUserModel(userModel)
        date = token.last_activation + datetime.timedelta(hours=2)
        return TokenResponseModel(token.token, date, rol.rol)
    else:
        raise Exception ("Invalid User Model")
예제 #9
0
 def create(self, username, email):
     # this is validation of the user input, requests model and view update callbacks
     if '@' not in email:
         self.view.update_display(False, 'Email not valid')
     else:
         user = UserModel.User(username, email)
         result = user.store_user()
         if result:
             self.view.update_display(True, 'User created!')
예제 #10
0
 def validUsername(self):
     if self.USER_RE.match(self.u):
         if Users.getUser(self.u):
             self.errors[0] = "that usernmae already exists"
             return False
         self.errors[0] = ""
         return True
     else:
         self.errors[0] = "That is not a valid username"
         return False
예제 #11
0
파일: fe.py 프로젝트: goors/flask-microblog
def read(slug=None):

    from models import db
    tag = TagModel()
    post = PostModel()
    comment = CommentModel()
    id = post.post(slug)

    id.NoOfViews += 1
    db.session.commit()

    postFiles = post.getPostFiles(id.Id)

    if request.method == "POST":

        if 'comment' in request.form and 'cid' not in request.form:

            comment.addcomment(request.form['comment'], request.form['email'], request.form['nick'], id.Id)

        if 'comment' in request.form and 'cid' in request.form:

            comment.addcomment(request.form['comment'], request.form['email'], request.form['nick'], id.Id, request.form['cid'])

            ##send reply to if any email address defined
            c = comment.getCommentEmail(request.form['cid'])
            if c.Email:
                from UserModel import UserModel
                u = UserModel()
                u.send_email(request.form['nick'] + " just commented on post "+id.Title, c.Email, request.form['comment']+ "<p>"+URL_FE+"read/"+id.Slug+"</p>", c.Nick)

        if 'password' in request.form:

            from werkzeug import check_password_hash

            if check_password_hash(id.Password, request.form['password']):
                t = render_template("home/read.html", tags=tag.tags(), post=post.post(slug), comments = comment.comments(id), postFiles=postFiles)
                return html_minify(unicode(t).encode('utf-8'))

    if id.Password != 'NULL':
        t = render_template("home/read-with-password.html", tags=tag.tags(), post=post.post(slug), comments = comment.comments(id), postFiles=postFiles)
    else:
        t = render_template("home/read.html", tags=tag.tags(), post=post.post(slug), comments = comment.comments(id), postFiles=postFiles)
    return html_minify(unicode(t).encode('utf-8'))
예제 #12
0
 def validUsername(self):
     if self.USER_RE.match(self.u):
         if Users.getUser(self.u):
             self.errors[0] = "that usernmae already exists"
             return False
         self.errors[0] = ""
         return True
     else:
         self.errors[0] = "That is not a valid username"
         return False
예제 #13
0
파일: install.py 프로젝트: cslab-uprrp/toa
def createUser():

	print ("""Creating user for the web interface.""")

	email=raw_input("Enter your email to be used as user account: ")
	while re.match("([a-zA-Z0-9]|\.|_|-|\+|$)+@[a-zA-Z0-9]+(\.[a-zA-Z]+)+$",email)==None:
        	print "Error: not a valid email adress"
        	email=raw_input("Enter email: ")

	print "Insert password for user %s" % email
	print "(at least 8 characters and at least one number, one letter and one unique character)"
	userpass=getpasswd()
	user=UserModel()
	if user.connect(DB_NAME,DB_USER, DB_PASS,flowpath,graphpath,crontime):
		user.Create('Admin',"55555555555",userpass,email,1)
	else:
        	print "ERROR: Database Connection Error\n"
        	print "Exiting installation with errors"
        	c.close()
        	exit(1)
def insert():
    d.append(0)
    for i in range(1, n_destination):
        d.append(random.uniform(10, 50))

    assignDistance()

    for i in range(n_users):
        org = int(random.uniform(0, n_destination - 1))
        dest = int(random.uniform(org + 1, n_destination))
        dist = distance[org][dest]
        q.append(um.User(org, dest, dist))
예제 #15
0
 def __init__(self, domainString, error_rate):
     '''
     '''
     self.um = UserModel.UM(domainString)
     self.error_simulator = ErrorModel.DomainsErrorSimulator(domainString, error_rate)
     
     self.randomLearning = False
     if Settings.config.has_option("mogp_"+domainString, "randomweightlearning"):
         self.randomLearning = Settings.config.getboolean("mogp_"+domainString, "randomweightlearning")
         
     if self.randomLearning:
         import policy.morl.WeightGenerator as wg
         self.weightGen = wg.WeightGenerator(domainString)
예제 #16
0
    def __init__(self, domainString, error_rate, ontology, cfg, logger,
                 SetObj):
        '''
        '''
        self.SetObj = SetObj
        self.um = UserModel.UM(domainString, ontology, cfg, logger, SetObj)
        self.error_simulator = ErrorModel.DomainsErrorSimulator(
            domainString, error_rate, ontology, cfg, logger, SetObj)

        self.randomLearning = False
        if cfg.has_option("mogp_" + domainString, "randomweightlearning"):
            self.randomLearning = cfg.getboolean("mogp_" + domainString,
                                                 "randomweightlearning")

        if self.randomLearning:
            import policy.morl.WeightGenerator as wg
            self.weightGen = wg.WeightGenerator(domainString)
예제 #17
0
def eval(args):
    def logging(s, print_=True, log_=False):
        if print_:
            print(s)
        return

    logging(str(args))

    # load image features (or compute and store them if necessary)
    fts = load_test_image_features(args)

    # user model: captioner
    captioner = UserModel.UserModel(args, mode='greedy')
    captioner.to(device)

    # ranker
    checkpoint_model = torch.load(
        os.path.join(args.trained_model, 'checkpoint_model.th'))
    retriever = checkpoint_model['retrieval_model']
    opt = checkpoint_model['args']

    print("=" * 88)
    print(opt)
    print("=" * 88)

    retriever.eval()
    logging('-' * 77)

    with torch.no_grad():
        metrics, ret_results = eval_batch(fts, captioner, retriever, opt)
    res = metrics['ranking_tracker']
    logging('|eval loss: {:8.3f} | score {:8.5f} | '
            'rank {:5.3f}/{:5.3f}/{:5.3f}/{:5.3f}/{:5.3f} | time:{}'.format(
                metrics['loss'], metrics['score'], 1 - res[0], 1 - res[1],
                1 - res[2], 1 - res[3], 1 - res[4], metrics['retrieve_time']))
    logging('-' * 77)

    with open(
            'prediction.test.{}.u{}.l{}.json'.format(opt.data_set,
                                                     opt.hidden_unit_num,
                                                     opt.layer_num), 'w') as f:
        json.dump(ret_results, f, indent=4)
    logging('evaluation complete')
예제 #18
0
def train(args):
    save_folder = '{}/{}'.format(args.save, args.data_set)
    create_exp_dir(save_folder)

    def logging(s, print_=True, log_=True):
        if print_:
            print(s)
        if log_:
            with open(os.path.join(save_folder, 'log.txt'), 'a+') as f_log:
                f_log.write(s + '\n')
        return

    logging(str(args))

    # load image features (or compute and store them if necessary)
    fts, fts_dev = load_image_features(args)

    # user model: captioner
    captioner = UserModel.UserModel(args)
    captioner.to(device)

    # ranker
    img_dim = fts['image'].size(dim=1)

    # response encoder
    glove_emb_file = args.glove_emb_file.format(args.data_set)
    with open(glove_emb_file, 'rb') as f:
        glove_emb = pickle.load(f)

    retriever = RetrieverTransformer(captioner.get_vocab_size(), glove_emb,
                                     img_dim, args.hidden_unit_num,
                                     args.layer_num,
                                     args.attribute_num).to(device)

    # Loss and optimizer
    params = retriever.parameters()
    optimizer = torch.optim.Adam(params, lr=args.learning_rate)

    current_lr = args.learning_rate
    cur_patient = 0
    best_score = float('-inf')
    best_train_score = float('-inf')

    for epoch in range(100):
        retriever.train()
        metrics = eval_batch(fts,
                             captioner,
                             retriever,
                             args,
                             train_mode=True,
                             optimizer=optimizer)
        res = metrics['ranking_tracker']
        logging('| ({}) train loss: {:8.5f} | lr: {:8.7f} | '
                'score {:8.5f} / {:8.5f} | '
                'rank {:5.3f}/{:5.3f}/{:5.3f}/{:5.3f}/{:5.3f}'.format(
                    epoch, metrics['loss'], current_lr, metrics['score'],
                    best_train_score, 1 - res[0], 1 - res[1], 1 - res[2],
                    1 - res[3], 1 - res[4]))
        logging('-' * 77)

        if metrics['score'] < best_train_score + 1e-3:
            cur_patient += 1
            if cur_patient >= args.patient:
                current_lr *= 0.5
                if current_lr < args.learning_rate * 1e-1:
                    break
                params = retriever.parameters()
                optimizer = torch.optim.Adam(params, lr=current_lr)

        best_train_score = max(metrics['score'], best_train_score)

        # eval on validation split
        if epoch % args.checkpoint == 0:
            retriever.eval()
            logging('-' * 77)

            with torch.no_grad():
                metrics = eval_batch(fts_dev, captioner, retriever, args)
            res = metrics['ranking_tracker']
            logging('| ({}) eval loss: {:8.3f} | score {:8.5f} / {:8.5f} | '
                    'rank {:5.3f}/{:5.3f}/{:5.3f}/{:5.3f}/{:5.3f}'.format(
                        epoch, metrics['loss'], metrics['score'], best_score,
                        1 - res[0], 1 - res[1], 1 - res[2], 1 - res[3],
                        1 - res[4]))
            logging('-' * 77)
            dev_score = metrics['score']

            if dev_score > best_score:
                best_score = dev_score
                # save best model
                checkpoint_model = {'args': args, 'retrieval_model': retriever}
                torch.save(checkpoint_model,
                           os.path.join(save_folder, 'checkpoint_model.th'))
                cur_patient = 0

    logging('best_dev_score: {}'.format(best_score))
예제 #19
0
def adduser():
    user = UserModel()

    if request.method == "POST":
        u = user.register(request.form['email'], request.form['password'], request.form['nick'], request.form['role'])
    return redirect("/admin/edit-user/"+u)
예제 #20
0
 def __init__(self, domainString):
     # User model
     self.um = UserModel.UM(domainString)
예제 #21
0
def users():
    user = UserModel();
    return render_template("admin/users.html", users=user.list())
예제 #22
0
def validateLogin(username, password):
    if (Users.getUser(username)
            and validatePassword(password, Users.getPassword(username))):
        return True
    else:
        return False
예제 #23
0
파일: install.py 프로젝트: cheojr/toa
print ("""Creating User 'toa' as admin for  the web interface""")
print "Insert password for admin 'toa'"

userpass=getpasswd()
phone=raw_input("Enter phone number(only digits)\n")
while re.match("[0-9]{7,20}$",phone)==None :
	print "ERROR: not a valid phone number (use only digits)"
	phone=raw_input("Enter phone number(only digits)\n")

email=raw_input("Enter email\n")
while re.match("([a-zA-Z0-9]|\.|_|-|\+|$)+@[a-zA-Z0-9]+(\.[a-zA-Z]+)+$",email)==None:
	print "Error: not a valid email adress"
	email=raw_input("Enter email\n")


user=UserModel()
if user.connect('Toa','toa',userpass,flowpath,graphpath,crontime):
	
	user.Create('toa',phone,userpass,email,1)
else:
	print "ERROR: Database Connection Error\n"
	print "Make sure the user 'toa' doesn't exist already"
	print "Exiting installation with errors"
	c.close()
	exit(1)

print("Done, you are now able to log in as admin using the toaoverlord user")


c.close()
예제 #24
0
파일: fe.py 프로젝트: goors/flask-microblog
 def getnick(id):
     u = UserModel()
     user = u.getUser(id)
     return user.Nick