Skip to content

Commit c510099

Browse files
author
Peter Shafer
committed
Merge pull request #8 from Tivix/issue_6-DRA03
Issue 6 - Django Rest Auth 0.3.0 Support
2 parents 939af5e + 6e4b40c commit c510099

File tree

11 files changed

+43
-37
lines changed

11 files changed

+43
-37
lines changed

app/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<div class="container">
2828
<div class="header">
2929
<ul class="nav nav-pills pull-right">
30-
<li class="active"><a ng-href="#">Home</a></li>
30+
<li class="active"><a ng-href="#/">Home</a></li>
3131
</ul>
3232
<h3 class="text-muted">Angular Django Registration Auth Demo</h3>
3333
</div>
@@ -54,7 +54,7 @@ <h3 class="text-muted">Angular Django Registration Auth Demo</h3>
5454

5555
<!-- build:js scripts/vendor.js -->
5656
<!-- bower:js -->
57-
<script src="bower_components/jquery/jquery.js"></script>
57+
<script src="bower_components/jquery/dist/jquery.js"></script>
5858
<script src="bower_components/angular/angular.js"></script>
5959
<script src="bower_components/bootstrap/dist/js/bootstrap.js"></script>
6060
<script src="bower_components/angular-resource/angular-resource.js"></script>

app/scripts/controllers/login.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ angular.module('angularDjangoRegistrationAuthApp')
1414
$location.path("/");
1515
},function(data){
1616
// error case
17-
$scope.error = data.error;
17+
$scope.errors = data;
1818
});
1919
}
2020
}

app/scripts/controllers/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ angular.module('angularDjangoRegistrationAuthApp')
4545
}
4646

4747
$scope.updateProfile = function(){
48-
djangoAuth.updateProfile(prompt("First Name"), prompt("Last Name"), prompt("Email"))
48+
djangoAuth.updateProfile({'first_name': prompt("First Name"), 'last_name': prompt("Last Name"), 'email': prompt("Email")})
4949
.then(handleSuccess,handleError);
5050
}
5151

app/scripts/controllers/register.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ angular.module('angularDjangoRegistrationAuthApp')
88
$scope.errors = [];
99
Validate.form_validation(formData,$scope.errors);
1010
if(!formData.$invalid){
11-
djangoAuth.register($scope.model.username,$scope.model.password,$scope.model.email)
11+
djangoAuth.register($scope.model.username,$scope.model.password1,$scope.model.password2,$scope.model.email)
1212
.then(function(data){
1313
// success case
1414
$scope.complete = true;
1515
},function(data){
1616
// error case
17-
$scope.errors = data.user;
17+
$scope.errors = data;
1818
});
1919
}
2020
}

app/scripts/controllers/userprofile.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ angular.module('angularDjangoRegistrationAuthApp')
55
$scope.model = {'first_name':'','last_name':'','email':''};
66
$scope.complete = false;
77
djangoAuth.profile().then(function(data){
8-
$scope.model = data.user;
8+
$scope.model = data;
99
});
10-
$scope.updateProfile = function(formData){
10+
$scope.updateProfile = function(formData, model){
1111
$scope.errors = [];
1212
Validate.form_validation(formData,$scope.errors);
1313
if(!formData.$invalid){
14-
djangoAuth.updateProfile($scope.model.first_name, $scope.model.last_name, $scope.model.email)
14+
djangoAuth.updateProfile(model)
1515
.then(function(data){
1616
// success case
1717
$scope.complete = true;

app/scripts/controllers/verifyemail.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
angular.module('angularDjangoRegistrationAuthApp')
44
.controller('VerifyemailCtrl', function ($scope, $routeParams, djangoAuth) {
55
djangoAuth.verify($routeParams["emailVerificationToken"]).then(function(data){
6-
$scope.success = data.success;
6+
$scope.success = true;
77
},function(data){
8-
$scope.failure = data.errors;
8+
$scope.failure = false;
99
});
1010
});

app/scripts/services/djangoAuth.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,18 @@ angular.module('angularDjangoRegistrationAuthApp')
6464
}));
6565
return deferred.promise;
6666
},
67-
'register': function(username,password,email){
67+
'register': function(username,password1,password2,email,more){
68+
var data = {
69+
'username':username,
70+
'password1':password1,
71+
'password2':password2,
72+
'email':email
73+
}
74+
data = angular.extend(data,more);
6875
return this.request({
6976
'method': "POST",
70-
'url': "/register/",
71-
'data':{
72-
'username':username,
73-
'password':password,
74-
'email':email
75-
}
77+
'url': "/registration/",
78+
'data' :data
7679
});
7780
},
7881
'login': function(username,password){
@@ -96,7 +99,7 @@ angular.module('angularDjangoRegistrationAuthApp')
9699
'logout': function(){
97100
var djangoAuth = this;
98101
return this.request({
99-
'method': "GET",
102+
'method': "POST",
100103
'url': "/logout/"
101104
}).then(function(data){
102105
delete $http.defaults.headers.common.Authorization;
@@ -130,30 +133,27 @@ angular.module('angularDjangoRegistrationAuthApp')
130133
'url': "/user/"
131134
});
132135
},
133-
'updateProfile': function(first_name,last_name,email){
136+
'updateProfile': function(data){
134137
return this.request({
135-
'method': "POST",
138+
'method': "PATCH",
136139
'url': "/user/",
137-
'data':{
138-
'user':{
139-
'first_name':first_name,
140-
'last_name':last_name,
141-
'email':email
142-
}
143-
}
140+
'data':data
144141
});
145142
},
146143
'verify': function(key){
147144
return this.request({
148-
'method': "GET",
149-
'url': "/verify-email/"+key+"/"
145+
'method': "POST",
146+
'url': "/registration/verify-email/",
147+
'data': {'key': key}
150148
});
151149
},
152-
'confirmReset': function(code1,code2,password1,password2){
150+
'confirmReset': function(uid,token,password1,password2){
153151
return this.request({
154152
'method': "POST",
155-
'url': "/password/reset/confirm/"+code1+"/"+code2+"/",
153+
'url': "/password/reset/confirm/",
156154
'data':{
155+
'uid': uid,
156+
'token': token,
157157
'new_password1':password1,
158158
'new_password2':password2
159159
}

app/views/login.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<input name="password" id="id_password" type="password" ng-model="model.password" placeholder="Password" class="form-control" required />
1111
</div>
1212
<div class="alert alert-danger" ng-repeat="error in errors.password">{{error}}</div>
13+
<div class="alert alert-danger" ng-repeat="error in errors.non_field_errors">{{error}}</div>
1314
<div class="alert alert-danger" ng-if="error">{{error}}</div>
1415
<button type="submit" class="btn btn-primary">Login</button>
1516
</form>

app/views/register.html

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@
88
<div class="alert alert-danger" ng-repeat="error in errors.username">{{error}}</div>
99
<div class="form-group">
1010
<label for="id_password">Password</label>
11-
<input name="password" id="id_password" class="form-control" type="password" ng-model="model.password" placeholder="Password" required />
11+
<input name="password1" id="id_password1" class="form-control" type="password" ng-model="model.password1" placeholder="Password" required />
1212
</div>
13-
<div class="alert alert-danger" ng-repeat="error in errors.password">{{error}}</div>
13+
<div class="alert alert-danger" ng-repeat="error in errors.password1">{{error}}</div>
14+
<div class="form-group">
15+
<label for="id_password">Repeat Password</label>
16+
<input name="password" id="id_password2" class="form-control" type="password" ng-model="model.password2" placeholder="Repeat Password" required />
17+
</div>
18+
<div class="alert alert-danger" ng-repeat="error in errors.password2">{{error}}</div>
1419
<div class="form-group">
1520
<label for="id_email">Email</label>
1621
<input name="email" id="id_email" class="form-control" type="email" ng-model="model.email" placeholder="Email" required />

app/views/userprofile.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div id="userProfile_view" ng-controller="UserprofileCtrl">
22
<div ng-if="complete == false">
3-
<form role="form" ng-if="authenticated" name="userProfileForm" ng-submit="updateProfile(userProfileForm)" novalidate>
3+
<form role="form" ng-if="authenticated" name="userProfileForm" ng-submit="updateProfile(userProfileForm, model)" novalidate>
44
<div class="form-group">
55
<label for="id_first_name">First Name</label>
66
<input name="first_name" id="id_first_name" class="form-control" type="text" ng-model="model.first_name" placeholder="First Name" />

0 commit comments

Comments
 (0)