Advertisement
Guest User

Untitled

a guest
Apr 4th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.15 KB | None | 0 0
  1. public class Startup
  2. {
  3. public Startup(IHostingEnvironment env)
  4. {
  5. var builder = new ConfigurationBuilder()
  6. .SetBasePath(env.ContentRootPath)
  7. .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
  8. .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
  9. .AddEnvironmentVariables();
  10. Configuration = builder.Build();
  11.  
  12. }
  13.  
  14. public IConfigurationRoot Configuration { get; }
  15.  
  16. // This method gets called by the runtime. Use this method to add services to the container.
  17. public void ConfigureServices(IServiceCollection services)
  18. {
  19.  
  20. services.AddDistributedMemoryCache(); // Adds a default in-memory implementation of IDistributedCache
  21. services.AddSession();
  22. services.AddSingleton<ITempDataProvider, CookieTempDataProvider>();
  23.  
  24.  
  25. services.AddCors(options =>
  26. {
  27. options.AddPolicy("AllowAllOrigins",builder => builder.AllowAnyOrigin().AllowAnyHeader());
  28. options.AddPolicy("AllowAllHeaders", builder => builder.AllowAnyHeader());
  29. options.AddPolicy("AllowCredentials", builder => builder.AllowCredentials());
  30. });
  31. services.Configure<IISOptions>(options =>
  32. {
  33. options.AutomaticAuthentication = true;
  34. options.ForwardClientCertificate = true;
  35. options.ForwardWindowsAuthentication = true;
  36. });
  37.  
  38. }
  39.  
  40. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  41. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
  42. {
  43. loggerFactory.AddConsole(Configuration.GetSection("Logging"));
  44. loggerFactory.AddDebug();
  45.  
  46. if (env.IsDevelopment())
  47. {
  48. app.UseDeveloperExceptionPage();
  49.  
  50. // Browser Link is not compatible with Kestrel 1.1.0
  51. // For details on enabling Browser Link, see https://go.microsoft.com/fwlink/?linkid=840936
  52. // app.UseBrowserLink();
  53. }
  54. else
  55. {
  56. app.UseExceptionHandler("/Home/Error");
  57. }
  58.  
  59. //app.UseDefaultFiles();
  60. ////app.UseStaticFiles();
  61. app.UseStaticFiles();
  62. app.UseFileServer();
  63.  
  64. app.UseCors("AllowAllOrigins");
  65. app.UseCors("AllowAllHeader");
  66.  
  67. // IMPORTANT: This session call MUST go before UseMvc()
  68. app.UseSession();
  69.  
  70. }
  71. }
  72.  
  73. angular
  74. .module('common.services')
  75. .factory('loginservice', ['$http', 'appSettings', loginservice]);
  76.  
  77. function loginservice($http, appSettings) {
  78.  
  79. this.login = function () {
  80. var resp = $http({
  81. url: appSettings.serverPath + 'token',
  82. method: 'POST',
  83. data: $.param({grant_type: 'password', username: appSettings.username, password: appSettings.password }),
  84.  
  85. headers: {
  86. 'Content-Type': 'application/x-www-form-urlencoded' }
  87. });
  88. return resp;
  89. };
  90. return { login: this.login }
  91. }
  92.  
  93. LoginController.js
  94.  
  95. app.controller('logincontroller', ['$scope', 'loginservice', 'userProfile', '$rootScope', logincontroller]);
  96.  
  97. function logincontroller($scope, loginservice, userProfile, $rootScope) {
  98. $scope.title = 'logincontroller';
  99.  
  100. $scope.IniciarLogin = function () {
  101.  
  102. var loginResult = loginservice.login();
  103.  
  104. loginResult.then(function (resp) {
  105.  
  106. userProfile.setProfile(resp.data.userName, resp.data.access_token, resp.data.refresh_token);
  107. }, function (response) {
  108.  
  109. alert("error");
  110. });
  111.  
  112. }
  113.  
  114.  
  115. $scope.logout = function () {
  116. sessionStorage.removeItem('accessToken');
  117. if (sessionStorage.getItem('userSessionName') != null){
  118. sessionStorage.removeItem('userSessionName');
  119. }
  120. }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement