Exemplo n.º 1
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for(".dashboard"))
    form = RegisterForm()
    if form.validate_on_submit():
        developer = Developer(
            first_name=form.first_name.data,
            last_name=form.last_name.data,
            email_id=form.email_id.data,
        )
        db.session.add(developer)
        login_otp = developer.create_login_otp()
        db.session.commit()

        try:
            send_login_mail(form.email_id.data, login_otp)
        except Exception as e:
            current_app.logger.error("Unable to Email.")
            current_app.logger.error(e)

        session["developer_email"] = developer.email_id

        return redirect(url_for(".otp_verify"))

    return render_template("home/register.html", form=form)
Exemplo n.º 2
0
def signup():

    """
    开发者用户注册
    """

    if request.method == 'GET':
        return render_template('signup.html')

    username = request.form['username']
    password = request.form['password']
    email = request.form['email']
    repassword = request.form['repassword']

    # 错误码判断
    if username.strip() == '' or repassword.strip() == '' \
            or password.strip() == '' or email.strip() == '':
        return jsonify({'status':401})

    if repassword != password:
        return jsonify({'status':402})

    if Developer.query.filter_by(username=username).first() != None \
            or Developer.query.filter_by(email=email).first() != None:
        return jsonify({'status':403})

    developer = Developer(username=username, password=password, email=email)

    try:
        developer.save()
    except Exception, e:
        print e
Exemplo n.º 3
0
 def create_developer_account(self):
     user = self.create_user_account()
     developer = Developer.query.filter_by(user_id=user.id).first()
     if developer is None:
         try:
             developer = Developer(user_id=user.id,
                                   name='Awesome Devs',
                                   website='http://www.devs.com')
             db.session.add(developer)
         except IntegrityError as e:
             db.session.rollback()
     return developer
Exemplo n.º 4
0
def register_developer():
    form = RegistrationDeveloperForm()
    if form.validate_on_submit():
        role_developer = SystemRole.query.filter_by(name=role_developer_name).first()
        user_developer = SystemUser(login=form.login.data, password=form.password.data, system_role=role_developer,
                              enabled=form.enabled.data)
        developer = Developer(fio=form.fio.data, system_user=user_developer)
        db.session.add(user_developer)
        db.session.add(developer)
        flash('разработчик {} создан.'.format(form.login.data))
        return redirect(url_for('.developers_list'))
    return render_template('users/form_register_edit.html', form=form, class_name='разработчика', creating=True)
Exemplo n.º 5
0
def create_developer():
    role_developer = SystemRole.query.filter_by(
        name=role_developer_name).first()
    user_developer = SystemUser(login='******',
                                password='******',
                                system_role=role_developer,
                                enabled=True)
    developer = Developer(fio='аккаунт разработчика',
                          system_user=user_developer)
    db.session.add(user_developer)
    db.session.add(developer)
    db.session.commit()
Exemplo n.º 6
0
def register_developer():
    form = RegisterDeveloperForm()
    login_form = LoginForm()
    if form.validate_on_submit():
        # Check username is not already taken
        if User.query.filter_by(primary_email=form.email.data).first():
            flash(
                'An account has already been registered with this email address.'
            )
        elif User.query.filter_by(id=form.user_name.data).first():
            flash('Username already taken.')
        else:
            cv = CV(document=form.upload_cv.data)
            dev = Developer(cv=cv)
            display_name = form.display_name.data if form.display_name.data != '' \
                else form.user_name.data
            user = User(id=form.user_name.data,
                        password=generate_password_hash(form.password.data),
                        display_name=display_name,
                        description=form.description.data,
                        primary_email=form.email.data,
                        developer=dev)
            #email_addresses=[email], developer=dev)
            db.session.add(user)
            db.session.commit()

            # Generate and send email
            token = generate_confirmation_token(user.primary_email)
            try:
                if app.config['BEHIND_HTTPS_PROXY']:
                    confirm_url = url_for('auth.confirm_email', token=token, \
                        _external=True, _scheme='https')
                else:
                    confirm_url = url_for('auth.confirm_email', token=token, \
                        _external=True)
            except KeyError:
                confirm_url = url_for('auth.confirm_email', token=token, \
                    _external=True)

            html = render_template('email/confirm_user_email.html', \
                confirm_url=confirm_url)
            subject = 'Dreaming Spires email confirmation'
            send_email(user.primary_email, subject, html)

            return render_template('auth/thanks_for_registering.html')

    return render_template('auth/register_developer.html', form=form, login_form=login_form, \
        entries=list(range(1000)))
Exemplo n.º 7
0
def agrega_developer(request):

    mensaje = ""
    alertOk = False
    alertError = False

    list_usuarios = User.objects.all()

    productOwner = User.objects.get(id=request.user.id)
    lista_proyectos = Proyecto.objects.filter(productOwner=productOwner)

    idProyecto = request.POST['proyecto']
    idUsuario = request.POST['usuario']

    proyecto = Proyecto.objects.get(id=idProyecto)
    usuario = User.objects.get(id=idUsuario)

    developer = Developer.objects.filter(
        Q(idUser=usuario) & Q(idProyecto=proyecto))

    if not developer:
        developer = Developer()
        developer.idProyecto = proyecto
        developer.idUser = usuario
        developer.activo = 'A'
        developer.save()

        mensaje = "El usuario fue agregado exitosamente"
        alertOk = True
    else:
        mensaje = "El usuario ya estaba agregado"
        alertError = True

    contexto = {
        'lista_proyectos': lista_proyectos,
        'lista_usuarios': list_usuarios,
        'mensaje': mensaje,
        'alertOk': alertOk,
        'alertError': alertError
    }

    return render(request, "app/agregar_developer.html", contexto)
Exemplo n.º 8
0
    def add_developers(self):
        developers = [{
            "email": "*****@*****.**",
            "name": "Ushahidi",
            "website": "http://ushahidi.com"
        }, {
            "email": "*****@*****.**",
            "name": "Enketo",
            "website": "http://enketo.com"
        }, {
            "email": "*****@*****.**",
            "name": "Etherpad",
            "website": "http://etherpad.com"
        }, {
            "email": "*****@*****.**",
            "name": "Sahana",
            "website": "http://sahana.com"
        }]
        if Developer.query.count() < 1:
            try:
                for dev in developers:
                    user = User(email=dev['email'],
                                username=dev['name'],
                                password=dev['name'])
                    db.session.add(user)
                    db.session.flush()

                    developer = Developer(user_id=user.id,
                                          name=dev['name'],
                                          website=dev['website'])

                    db.session.add(developer)

                db.session.commit()
            except IntegrityError as e:
                db.session.rollback()
Exemplo n.º 9
0
def generate():
    # Generate a few users
    try:
        edd = User(id='edd',
                   password=generate_password_hash('e'),
                   display_name='Edd Salkield',
                   description='My description',
                   primary_email='*****@*****.**',
                   developer=Developer())
        edd_role = MailUserRole(user=edd,
                                creator=True,
                                relationship='Interested')
        edd_role_c = MailUserRole(user=edd,
                                  creator=True,
                                  relationship='Current')
        edd_role_p = MailUserRole(user=edd, creator=True, relationship='Past')
        edd_role_o = MailUserRole(user=edd, creator=True, relationship='Other')
        db.session.add(edd)
        db.session.add(edd_role)
        rogan = User(id='rogan',
                     password=generate_password_hash('e'),
                     display_name='Rogan Clark',
                     description='My description',
                     primary_email='*****@*****.**',
                     developer=Developer())
        rogan_role = MailUserRole(user=rogan,
                                  creator=False,
                                  relationship='Current')
        db.session.add(rogan)
        db.session.add(rogan_role)
        mark = User(id='mark',
                    password=generate_password_hash('e'),
                    display_name='Mark Todd',
                    description='My description',
                    primary_email='*****@*****.**',
                    developer=Developer())
        mark_role = MailUserRole(user=mark, creator=False, relationship='Past')
        db.session.add(mark)
        db.session.add(mark_role)
        josh = User(id='josh',
                    password=generate_password_hash('e'),
                    display_name='Josh Smailes',
                    description='My description',
                    primary_email='*****@*****.**',
                    developer=Developer())
        josh_role = MailUserRole(user=josh,
                                 creator=False,
                                 relationship='Other')
        db.session.add(josh)
        db.session.add(josh_role)

        # Generate some organisations
        oxford_cs = Department(display_name='Computer Science',
                               description='''
            Oxford CS description
        ''',
                               users=[edd])
        oxford_anthro = Department(display_name='Anthropology',
                                   description='''
            Oxford Anthropology description
        ''',
                                   users=[edd])
        oxford = Organisation(display_name='University of Oxford',
                              description='''
            This is the description of the Universty of Oxford
        ''',
                              departments=[oxford_cs, oxford_anthro])

        cambridge_anthro = Department(display_name='Anthropology',
                                      description='''
            Cambridge Anthropology description
        ''',
                                      users=[edd])
        cambridge = Organisation(display_name='University of Cambridge',
                                 description='''
            This is the description of the Universty of Cambridge 
        ''',
                                 departments=[cambridge_anthro])

        db.session.add(oxford)
        db.session.add(cambridge)

        # Generate a group chat
        user_roles = [edd_role, rogan_role, mark_role, josh_role]
        empty_group = MailGroup(display_name='The empty chat',
                                user_roles=user_roles)
        db.session.add(empty_group)

        group = MailGroup(display_name='The friend chat',
                          user_roles=user_roles)
        db.session.add(group)
        group = MailGroup(display_name='The current chat',
                          user_roles=[edd_role_c])
        db.session.add(group)
        group = MailGroup(display_name='The past chat',
                          user_roles=[edd_role_p])
        db.session.add(group)
        group = MailGroup(display_name='The other chat',
                          user_roles=[edd_role_o])
        db.session.add(group)
        db.session.commit()

        # Create some messages
        messages = []
        message = MailMessage(user=edd,
                              body='yo wassup',
                              date_created=datetime.utcnow())
        db.session.add(message)
        messages.append(message)
        time.sleep(2)
        message = MailMessage(user=josh,
                              body='nm',
                              date_created=datetime.utcnow())
        db.session.add(message)
        messages.append(message)
        time.sleep(2)
        message = MailMessage(user=mark,
                              body='nm 2',
                              date_created=datetime.utcnow())
        db.session.add(message)
        messages.append(message)
        db.session.commit()
        group.messages = messages

        # Save changes
        db.session.commit()
    except IntegrityError:
        db.session.rollback()
        group = MailGroup.query.filter_by(
            display_name='The friend chat').first()
        return f'messages already generated. Group id: {group.id}'
    else:
        return 'messages generated'
Exemplo n.º 10
0
def submit_email(request):

    developer_email = request.POST['email']

    # TODO handle session expiry
    if not request.session.__contains__('project'):
        logger.error("No project found in session, returning index page!")
        return render(request, 'app/index.html')

    project = request.session['project']

    if not EMAIL_REGEX.match(developer_email):
        logger.debug("Invalid email %s received" % developer_email)
        return render_project(request, project,
                              'Supplied email is not a valid email address.')

    logger.debug("Received email %s" % developer_email)

    verification_code = create_unique_code()

    stored_developer = Developer.objects.filter(email=developer_email)

    # Existing dev, verified email
    if stored_developer.exists():
        developer = stored_developer[0]
        logger.debug("Developer already known: %s" % developer)
        if developer.email_verified:
            logger.debug("Developer's mail already verified, proceeding...")
            context = {'verified_email': developer_email}
            developer.send_emails = True
            developer.save()
        else:
            # existing dev, email not verified yet
            logger.debug(
                "Developer's mail not yet verified, recreating the code...")
            developer.email_verification_code = verification_code
            developer.email_verification_timestamp = datetime.utcnow()
            developer.save()
            send_verification_email(developer_email, verification_code)
            context = {'unverified_email': developer_email}

    else:
        # new developer
        logger.debug("New developer, creating a db entry...")
        developer = Developer(email=developer_email,
                              email_verification_code=verification_code,
                              email_verification_timestamp=datetime.utcnow(),
                              email_verified=False,
                              send_emails=True,
                              unsubscribe_code=create_unique_code())
        developer.save()
        send_verification_email(developer_email, verification_code)
        context = {'unverified_email': developer_email}

    # Create developer specific project
    stored_projects = Project.objects.filter(developer=developer,
                                             namespace=project.group_id,
                                             name=project.artifact_id)

    if stored_projects.exists():
        stored_project = stored_projects[0]
        logger.debug("Project %s already stored, resetting dependencies..." %
                     stored_project)
        stored_project.send_updates = True
        stored_project.save()
        ProjectDependency.objects.filter(project=stored_project).delete()
        maven_project = stored_project
    else:
        maven_project = Project(developer=developer,
                                namespace=project.group_id,
                                name=project.artifact_id,
                                version=project.version,
                                send_updates=True,
                                unsubscribe_code=create_unique_code())
        logger.debug("New project %s, creating a db entry..." % maven_project)
        maven_project.save()

    # Mark its dependencies
    for dto in project.dependencies:
        repo_dependencies = RepoDependency.objects.filter(
            namespace=dto.group_id, name=dto.artifact_id)
        if repo_dependencies.exists():
            repo_dependency = repo_dependencies[0]
        else:
            repo_dependency = None
        project_dependency = ProjectDependency(project=maven_project,
                                               repo_dependency=repo_dependency,
                                               namespace=dto.group_id,
                                               name=dto.artifact_id,
                                               version=dto.version)
        project_dependency.save()

    return render(request, 'app/email-verification.html', context)