def do_user_import(): if not request.files['file']: return render_template('importusers.html', admin = UserManager.get(store, session.get('userid'))[1].admin) users = [] reader = csv.reader(request.files['file']) for id, name, mail, password, salt, admin, lfmsess, lfmstatus in reader: mail = None if mail == 'None' else mail admin = admin == 'True' lfmsess = None if lfmsess == 'None' else lfmsess lfmstatus = lfmstatus == 'True' user = User() user.id = uuid.UUID(id) user.name = name user.password = password user.salt = salt user.admin = admin user.lastfm_session = lfmsess user.lastfm_status = lfmstatus users.append(user) store.find(User).remove() for u in users: store.add(u) store.commit() return redirect(url_for('user_index'))
def do_user_import(): if not request.files['file']: return render_template('importusers.html') users = [] reader = csv.reader(request.files['file']) for id, name, mail, password, salt, admin, lfmsess, lfmstatus in reader: mail = None if mail == 'None' else mail admin = admin == 'True' lfmsess = None if lfmsess == 'None' else lfmsess lfmstatus = lfmstatus == 'True' user = User() user.id = uuid.UUID(id) user.name = name user.password = password user.salt = salt user.admin = admin user.lastfm_session = lfmsess user.lastfm_status = lfmstatus users.append(user) store.find(User).remove() for u in users: store.add(u) store.commit() return redirect(url_for('user_index'))
def add(store, name, password, mail, admin): if store.find(User, User.name == name).one(): return UserManager.NAME_EXISTS crypt, salt = UserManager.__encrypt_password(password) user = User() user.name = name user.mail = mail user.password = crypt user.salt = salt user.admin = admin store.add(user) store.commit() return UserManager.SUCCESS