def user_update(id_data): if not User.is_admin(current_user.jabatan): return redirect(url_for('admin.dashboard')) form = UserForm() data = User.query.get(id_data) # check if data exist if data is None: return redirect(url_for('admin.user_data')) # post user form if form.validate_on_submit(): data.nama = form.nama.data data.username = form.username.data data.jabatan = form.jabatan.data data.status = form.status.data # check if password changed if len(form.password.data.strip()) > 0: data.password = User.hash_password(form.password.data) # if update data success if User.update(data): flash('Data berhasil diperbarui', 'success') return redirect(url_for('admin.user_data')) flash('Data gagal diperbarui', 'error') # return render_template('user_update.html', form=form, data=data) return redirect(url_for('admin.user_update')) return render_template('user_update.html', form=form, data=data, user_sidebar='active')
def profile(): form = UserProfileForm() if form.validate_on_submit(): data = User.query.get(int(current_user.id)) if len(str(form.password.data).strip()) > 0: data.password = User.hash_password(form.password.data) if len(str(form.nama.data).strip()) > 0: data.nama = form.nama.data if User.update(data): flash('Update profile berhasil!', 'success') return redirect(url_for('admin.profile')) return redirect(url_for('admin.profile')) return render_template('profile.html', form=form)