Exemplo n.º 1
0
def userUpdateSettings():
  if request.method == 'POST':
    form = UserSettingsForm(request.form)
    if form.validate():
      user = current_user
      user.firstName = bleach.clean(form.firstName.data)
      user.lastName = bleach.clean(form.lastName.data)
      if form.email.data == "None":
        user.email = None
      else:
        user.email = bleach.clean(form.email.data)

      f = request.files.getlist('photo')[0]
      if len(f.filename) > 0:
        if user.photoName != None:
          #Remove the existing photo
          os.remove(getUserPhotoPath(user))
        #We have to upload a new photo
        photoName = secure_filename(f.filename)
        name, extension = os.path.splitext(photoName)
        ensurePathExists(getUserPhotoDir())
        f.save(os.path.join(getUserPhotoDir(), str(g.user.id)+extension))
        user.photoName = str(g.user.id)+extension

      user.save()
      flash("Updated user information", "success")
      return redirect(url_for('userSettings'))
Exemplo n.º 2
0
def userUpdateSettings():
    if request.method == 'POST':
        form = UserSettingsForm(request.form)
        if form.validate():
            user = current_user
            user.firstName = bleach.clean(form.firstName.data)
            user.lastName = bleach.clean(form.lastName.data)
            if form.email.data == "None":
                user.email = None
            else:
                user.email = bleach.clean(form.email.data)

            f = request.files.getlist('photo')[0]
            if len(f.filename) > 0:
                if user.photoName != None:
                    #Remove the existing photo
                    os.remove(getUserPhotoPath(user))
                #We have to upload a new photo
                photoName = secure_filename(f.filename)
                name, extension = os.path.splitext(photoName)
                ensurePathExists(getUserPhotoDir())
                f.save(
                    os.path.join(getUserPhotoDir(),
                                 str(g.user.id) + extension))
                user.photoName = str(g.user.id) + extension

            user.save()
            flash("Updated user information", "success")
            return redirect(url_for('userSettings'))
Exemplo n.º 3
0
def sendProfilePicture(uid):
  try:
    user = User.objects.get(id=uid)
    if user.photoName != None:
      return send_file(getUserPhotoPath(user))
    else:
      return redirect(url_for('static', filename='images/defaultUser.png'))
  except Exception as e:
    return redirect(url_for('static', filename='images/defaultUser.png'))
Exemplo n.º 4
0
def sendProfilePicture(uid):
    try:
        user = User.objects.get(id=uid)
        if user.photoName != None:
            return send_file(getUserPhotoPath(user))
        else:
            return redirect(
                url_for('static', filename='images/defaultUser.png'))
    except Exception as e:
        return redirect(url_for('static', filename='images/defaultUser.png'))