def find_all(): """ Get all users from both scopes ('staff' and 'freelance') """ users = [] # will be a list of user object to return server = ldap.initialize("ldap://a52dc01") # TODO: need a better anonymous login for browsing AD server.simple_bind_s("rush", "area52") server.set_option(ldap.OPT_REFERRALS, 0) for scope in ['staff', 'freelance']: result_id = server.search('ou=%s,ou=a52,dc=a52,dc=com' % scope, ldap.SCOPE_SUBTREE, "cn=*") while 1: r_type, info = server.result(result_id, 0) if (info == []): break else: if r_type == 100: obj = User() user_id = info[0][1]['sAMAccountName'][0] #print "Adding %s user: %s" % (scope,user_id) obj.data = info[0][1] obj.user_id = user_id obj.cn = info[0][1]['cn'][0] obj.employment_status = scope users.append(obj) return users
def show_signup_form(): if current_user.is_authenticated: return redirect(url_for('index')) form = SignupForm() if form.validate_on_submit(): name = form.name.data email = form.email.data password = form.password.data # Creamos el usuario y lo guardamos user = User(len(users) + 1, name, email, password) users.append(user) # Dejamos al usuario logueado login_user(user, remember=True) next = request.args.get( 'next', None) #ACCION PARA HACER LUEGO DE ENVIAR EL FORMULARIO if next: return redirect(next) return redirect(url_for('index')) # EN CASO DE SOLO CAPTURAR LOS DATOS DEL FORMULARIO SIN UNA # if request.method == 'POST': # name = request.form['name'] # email = request.form['email'] # password = request.form['password'] return render_template("signup_form.html", form=form)
def find_by_user_id(user_id=None): """ Search Active Directory and return a User object for each result Note: for now the search is limited to department until I can accomodate the more complex searching used by ldap """ # The Active Directory (AD) is organized into 2 ou's, # staff and freelance, so 2 calls need to be made users = [] # will be a list of user object to return server = ldap.initialize("ldap://a52dc01") # TODO: need a better anonymous login for browsing AD server.simple_bind_s("rush", "area52") server.set_option(ldap.OPT_REFERRALS, 0) result_id = server.search('ou=staff,ou=a52,dc=a52,dc=com', ldap.SCOPE_SUBTREE, "sAMAccountName=%s" % user_id) while 1: r_type, info = server.result(result_id, 0) if (info == []): break else: if r_type == 100: obj = User() user_id = info[0][1]['sAMAccountName'][0] obj.data = info[0][1] obj.user_id = user_id obj.cn = info[0][1]['cn'][0] obj.employment_status = 'staff' users.append(obj) result_id = server.search('ou=freelance,ou=a52,dc=a52,dc=com', ldap.SCOPE_SUBTREE, "sAMAccountName=%s" % user_id) while 1: r_type, info = server.result(result_id, 0) if (info == []): break else: if r_type == 100: obj = User() user_id = info[0][1]['sAMAccountName'][0] obj.data = info[0][1] obj.user_id = user_id obj.cn = info[0][1]['cn'][0] obj.employment_status = 'freelance' users.append(obj) return users
def show_signup_form(): if current_user.is_authenticated: return redirect(url_for('index')) form = SignupForm() if form.validate_on_submit(): name = form.name.data email = form.email.data password = form.password.data # Creamos el usuario y lo guardamos user = User(len(users) + 1, name, email, password) users.append(user) # Dejamos al usuario logueado login_user(user, remember=True) next_page = request.args.get('next', None) if not next_page or url_parse(next_page).netloc != '': next_page = url_for('index') return redirect(next_page) return render_template("signup_form.html", form=form)
def find(department=None, user_id=None, title=None): if department: users = User.find_by_department(department=department) fk_users = User().find_fake_users(department=department) for u in fk_users: users.append(u) return users if user_id: users = User.find_by_user_id(user_id=user_id) if not users: return User().find_fake_users(user_id=user_id) # see if we have a fake user with this user_id return users if title: users = User.find_by_title(title) fk_users = User().find_fake_users(title=title) for u in fk_users: users.append(u) return users
def get_user(email): users = [] connection = cx_Oracle.connect("fbd/fbd@localhost:49161/xe") cur = connection.cursor() cur.execute("SELECT * FROM USUARIOS WHERE correo=:1", (email, )) col = cur.fetchall() for c in col: id = c[0] name = c[1] lastN = c[2] email = c[3] password = c[4] admin = True if c[5] == "1" else False users.append(User(id, name, lastN, email, password, is_admin=admin)) cur.close() connection.close() for user in users: print(user) if user.email == email: return user return None