Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Startup
- {
- public Startup(IHostingEnvironment env)
- {
- var builder = new ConfigurationBuilder()
- .SetBasePath(env.ContentRootPath)
- .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
- .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
- .AddEnvironmentVariables();
- Configuration = builder.Build();
- }
- public IConfigurationRoot Configuration { get; }
- // This method gets called by the runtime. Use this method to add services to the container.
- public void ConfigureServices(IServiceCollection services)
- {
- services.AddDistributedMemoryCache(); // Adds a default in-memory implementation of IDistributedCache
- services.AddSession();
- services.AddSingleton<ITempDataProvider, CookieTempDataProvider>();
- services.AddCors(options =>
- {
- options.AddPolicy("AllowAllOrigins",builder => builder.AllowAnyOrigin().AllowAnyHeader());
- options.AddPolicy("AllowAllHeaders", builder => builder.AllowAnyHeader());
- options.AddPolicy("AllowCredentials", builder => builder.AllowCredentials());
- });
- services.Configure<IISOptions>(options =>
- {
- options.AutomaticAuthentication = true;
- options.ForwardClientCertificate = true;
- options.ForwardWindowsAuthentication = true;
- });
- }
- // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
- public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
- {
- loggerFactory.AddConsole(Configuration.GetSection("Logging"));
- loggerFactory.AddDebug();
- if (env.IsDevelopment())
- {
- app.UseDeveloperExceptionPage();
- // Browser Link is not compatible with Kestrel 1.1.0
- // For details on enabling Browser Link, see https://go.microsoft.com/fwlink/?linkid=840936
- // app.UseBrowserLink();
- }
- else
- {
- app.UseExceptionHandler("/Home/Error");
- }
- //app.UseDefaultFiles();
- ////app.UseStaticFiles();
- app.UseStaticFiles();
- app.UseFileServer();
- app.UseCors("AllowAllOrigins");
- app.UseCors("AllowAllHeader");
- // IMPORTANT: This session call MUST go before UseMvc()
- app.UseSession();
- }
- }
- angular
- .module('common.services')
- .factory('loginservice', ['$http', 'appSettings', loginservice]);
- function loginservice($http, appSettings) {
- this.login = function () {
- var resp = $http({
- url: appSettings.serverPath + 'token',
- method: 'POST',
- data: $.param({grant_type: 'password', username: appSettings.username, password: appSettings.password }),
- headers: {
- 'Content-Type': 'application/x-www-form-urlencoded' }
- });
- return resp;
- };
- return { login: this.login }
- }
- LoginController.js
- app.controller('logincontroller', ['$scope', 'loginservice', 'userProfile', '$rootScope', logincontroller]);
- function logincontroller($scope, loginservice, userProfile, $rootScope) {
- $scope.title = 'logincontroller';
- $scope.IniciarLogin = function () {
- var loginResult = loginservice.login();
- loginResult.then(function (resp) {
- userProfile.setProfile(resp.data.userName, resp.data.access_token, resp.data.refresh_token);
- }, function (response) {
- alert("error");
- });
- }
- $scope.logout = function () {
- sessionStorage.removeItem('accessToken');
- if (sessionStorage.getItem('userSessionName') != null){
- sessionStorage.removeItem('userSessionName');
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement