def register(request): """Register new user with keystone; called from login page Needs error checking """ if request.method == "POST": form = forms.UserRegister(request.POST) if form.is_valid(): user_name = form.cleaned_data['user_name'] password = form.cleaned_data['password'] user = helpers.retrieve_object("User", "user_name", user_name) if user is None: new_user = models.User.create_user(user_name=user_name, password=password) new_user.save() request.session['user_name'] = user_name request.session['username'] = user_name request.session['password'] = password return HttpResponseRedirect('/projects') else: print "user %s exists" % user else: print form.errors return HttpResponseRedirect('/')
def clouds(request): """List projects and vms in user's clouds""" user = helpers.retrieve_object("User", "user_name", request.session['user_name']) if user is not None: try: projects = models.UIProject.objects.filter(users=user) #print projects except Exception as e: print e projects = [] else: return HttpResponseRedirect('/') project_list = [] for project in projects: vm_list = [] # for vm in models.VM.objects.filter(ui_project=project): # vm_list.append(vm) project_list.append({'name':project.name, 'vm_list': vm_list}) for project in dicts.test_project_list: project_list.append(project) return render(request, 'clouds.html', {'project_list': project_list, 'cloud_modals': html.cloud_modals(request), } )
def login(request): """View to Login a user Checks post credentials, redirects to projects or back to front page with error """ if request.method == 'POST': form = forms.Login(request.POST) if form.is_valid(): print "form is valid" user_name = form.cleaned_data['user_name'] password = form.cleaned_data['password'] user = helpers.retrieve_object("User", "user_name", user_name) if user is not None: print "verifying password" if user.verify_password(password=password): request.session['user_name'] = user_name request.session['username'] = user_name request.session['password'] = password return HttpResponseRedirect('/projects')