You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.7 KiB

4 years ago
  1. app.controller('UserController', function($scope, $http, $cookieStore, $modal, $modalInstance, $window, modal) {
  2. $scope.logg = modal.logg;
  3. $scope.closeModal = function () {
  4. $modalInstance.dismiss('cancel');
  5. };
  6. $scope.registerUser = function(register){
  7. $http({
  8. method: 'POST',
  9. url: serverURL+"/user/new",
  10. data: {
  11. user: register
  12. },
  13. headers: {'Content-Type': 'application/x-www-form-urlencoded'},
  14. }).success(function(data, status, headers, config) {
  15. if(data.success == "true"){
  16. $cookieStore.put('user',data);
  17. $window.location.reload();
  18. }else{
  19. modal = modalCreate($modal,"danger", "Error", "Email already in use.");
  20. }
  21. }).error(function(data, status, headers, config) {
  22. modal = modalCreate($modal,"danger", "Error", "Don't connected with server.");
  23. });
  24. };
  25. $scope.loginUser = function(login){
  26. $http({
  27. method: 'POST',
  28. url: serverURL+"/user/login",
  29. data: {
  30. user: login
  31. },
  32. headers: {'Content-Type': 'application/x-www-form-urlencoded'},
  33. }).success(function(data, status, headers, config) {
  34. if(data.success == "true"){
  35. $cookieStore.put('user',data);
  36. $window.location.reload();
  37. }else{
  38. modal = modalCreate($modal,"danger", "Error", "Invalid email or password.");
  39. }
  40. }).error(function(data, status, headers, config) {
  41. modal = modalCreate($modal,"danger", "Error", "Don't connected with server.");
  42. });
  43. };
  44. OAuth.initialize('YHWU5IeupujOH-Izgk6Wc9V3b5w'); // Yo
  45. $scope.clickConnect = function(provider) {
  46. OAuth.popup(provider).done(function(result) {
  47. //Get your user's personal data
  48. result.me().done(function(me) {
  49. var user = {};
  50. if(provider == "facebook"){
  51. result.get('me?fields=email').done(function(data) {
  52. var profile = me;
  53. profile.email = data.email;
  54. $scope.getSocialLogin(profile, provider);
  55. });
  56. }else if("google"){
  57. $scope.getSocialLogin(me, provider);
  58. }else if("twitter"){
  59. $scope.getSocialLogin(me, provider);
  60. }
  61. $scope.me = me;
  62. $scope.provider = provider;
  63. });
  64. })
  65. };
  66. $scope.getSocialLogin = function(data, provider){
  67. $http({
  68. method: 'POST',
  69. url: serverURL+"/user/social",
  70. data: {
  71. user: data,
  72. social: provider
  73. },
  74. headers: {'Content-Type': 'application/x-www-form-urlencoded'},
  75. }).success(function(data, status, headers, config) {
  76. if(data.success == "true"){
  77. $cookieStore.put('user',data);
  78. $window.location.reload();
  79. }else{
  80. modal = modalCreate($modal,"danger", "Error", "Invalid email or password.");
  81. }
  82. }).error(function(data, status, headers, config) {
  83. modal = modalCreate($modal,"danger", "Error", "Don't connected with server.");
  84. })
  85. };
  86. })