Guest User

Untitled

a guest
Sep 20th, 2018
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.10 KB | None | 0 0
  1. public async Task<IActionResult> Login(LoginViewModel model, string returnUrl = "/RealTimeChart/Index")
  2. {
  3. ViewData["ReturnUrl"] = returnUrl;
  4. if (ModelState.IsValid)
  5. {
  6. //ApplicationUser signedUser = await _userManager.FindByEmailAsync(model.Email);
  7. //var result = await _signInManager.PasswordSignInAsync(signedUser.UserName, model.Password, model.RememberMe, false);
  8.  
  9. var signedUser = await _userManager.FindByEmailAsync(model.Email);
  10. var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, lockoutOnFailure: true);
  11.  
  12. if (result.Succeeded)
  13. {
  14. _logger.LogInformation("User logged in.");
  15. return RedirectToLocal(returnUrl);
  16. }
  17. if (result.IsLockedOut)
  18. {
  19. _logger.LogWarning("User account locked out.");
  20. return RedirectToAction(nameof(Lockout));
  21. }
  22. else
  23. {
  24. ModelState.AddModelError(string.Empty, "Invalid login attempt.");
  25. return View(model);
  26. }
  27. }
  28.  
  29. // If we got this far, something failed, redisplay form
  30. return View(model);
  31. }
  32.  
  33. public class Startup
  34. {
  35. public Startup(IConfiguration configuration)
  36. {
  37. Configuration = configuration;
  38. }
  39.  
  40. public IConfiguration Configuration { get; }
  41.  
  42. // This method gets called by the runtime. Use this method to add services to the container.
  43. public void ConfigureServices(IServiceCollection services)
  44. {
  45. services.AddDbContext<ApplicationDbContext>(options =>
  46. options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
  47.  
  48. services.AddIdentity<ApplicationUser, IdentityRole>()
  49. .AddEntityFrameworkStores<ApplicationDbContext>()
  50. .AddDefaultTokenProviders();
  51.  
  52.  
  53. //Password Strength Setting
  54. services.Configure<IdentityOptions>(options =>
  55. {
  56. // Lockout settings
  57. options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(30);
  58. options.Lockout.MaxFailedAccessAttempts = 10;
  59. options.Lockout.AllowedForNewUsers = true;
  60.  
  61. // User settings
  62. options.User.RequireUniqueEmail = true;
  63. });
  64.  
  65. //Seting the Account Login page
  66. services.ConfigureApplicationCookie(options =>
  67. {
  68. // Cookie settings
  69. options.Cookie.HttpOnly = true;
  70. options.ExpireTimeSpan = TimeSpan.FromMinutes(30);
  71. options.LoginPath = "/Account/Login"; // If the LoginPath is not set here, ASP.NET Core will default to /Account/Login
  72. options.LogoutPath = "/Account/Logout"; // If the LogoutPath is not set here, ASP.NET Core will default to /Account/Logout
  73. options.AccessDeniedPath = "/Account/AccessDenied"; // If the AccessDeniedPath is not set here, ASP.NET Core will default to /Account/AccessDenied
  74. options.SlidingExpiration = true;
  75.  
  76. });
  77.  
  78. // Add application services.
  79. services.AddTransient<IEmailSender, AuthMessageSender>();
  80. services.AddTransient<ISmsSender, AuthMessageSender>();
  81. // Add services
  82. services.AddTransient<IContactManagement, ContactManagement>();
  83. services.AddTransient<IRepository<Contact>, Repository<Contact>>();
  84. services.AddTransient<IJobManagement, JobJobManagement>();
  85. services.AddTransient<IRepository<Job>, Repository<Job>>();
  86. services.AddTransient<IUnitManagement, UnitManagement>();
  87. services.AddTransient<IRepository<Sensor>, Repository<Sensor>>();
  88. services.AddTransient<IJobContactManagement, JobContactManagement>();
  89. services.AddTransient<IRepository<JobContact>, Repository<JobContact>>();
  90. services.AddTransient<IJobContactEventManagement, JobContactEventManagement>();
  91. services.AddTransient<IRepository<JobContactEvent>, Repository<JobContactEvent>>();
  92. services.AddTransient<IJobsensorManagement, JobsensorManagement>();
  93. services.AddTransient<IRepository<JobSensor>, Repository<JobSensor>>();
  94. services.AddTransient<IEventTypesManagement, EventTypesManagement>();
  95. services.AddTransient<IRepository<EventType>, Repository<EventType>>();
  96. services.AddTransient<IJobSensorLocationPlannedManagement, JobSensorLocationPlannedManagement>();
  97. services.AddTransient<IRepository<JobSensorLocationPlanned>, Repository<JobSensorLocationPlanned>>();
  98. services.AddTransient<IDataTypeManagement, DataTypeManagement>();
  99. services.AddTransient<IRepository<DataType>, Repository<DataType>>();
  100. services.AddTransient<IThresholdManegement, ThresholdManegement>();
  101. services.AddTransient<IRepository<Threshold>, Repository<Threshold>>();
  102. services.AddTransient<ISeverityTypeManagement, SeverityTypeManagement>();
  103. services.AddTransient<IRepository<SeverityType>, Repository<SeverityType>>();
  104. services.AddTransient<ISensorDataManagement, SensorDataManagement>();
  105. services.AddTransient<IRepository<SensorData>, Repository<SensorData>>();
  106. services.AddTransient<ISensorLocationManagement, SensorLocationManagement>();
  107. services.AddTransient<IRepository<SensorLocation>, Repository<SensorLocation>>();
  108.  
  109. services.AddTransient<ISensorStatusTypeManagement, SensorStatusTypeManagement>();
  110. services.AddTransient<IRepository<SensorStatusType>, Repository<SensorStatusType>>();
  111. services.AddTransient<IRepository<SensorDataToday>, Repository<SensorDataToday>>();
  112. services.AddTransient<ISensorDataTodayManagement, SensorDataTodayManagement>();
  113.  
  114. services.AddMvc();
  115. }
  116.  
  117. public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
  118. {
  119. public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
  120. : base(options)
  121. {
  122. }
  123.  
  124. // public object Jobs { get; set; }
  125.  
  126. protected override void OnModelCreating(ModelBuilder builder)
  127. {
  128. base.OnModelCreating(builder);
  129. // Customize the ASP.NET Identity model and override the defaults if needed.
  130. // For example, you can rename the ASP.NET Identity table names and more.
  131. // Add your customizations after calling base.OnModelCreating(builder);
  132. }
  133.  
  134. public DbSet<DataType> DataTypes { get; set; }
  135. public DbSet<UserAccountType> UserAccountTypes { get; set; }
  136. public DbSet<GeneralSetting> GeneralSettings { get; set; }
  137. public DbSet<Job> Jobs { get; set; }
  138. public DbSet<Log> Logs { get; set; }
  139. public DbSet<Sensor> Sensors { get; set; }
  140. public DbSet<SensorDataRaw> SensorDataRaw { get; set; }
  141. public DbSet<SensorDataRawArchive> SensorDataRawArchive { get; set; }
  142. public DbSet<SensorStatusType> SensorStatusTypes { get; set; }
  143. public DbSet<SeverityType> SeverityTypes { get; set; }
  144. public DbSet<StatusReportType> StatusReportTypes { get; set; }
  145. public DbSet<Contact> Contacts { get; set; }
  146. public DbSet<EventType> EventTypes { get; set; }
  147. public DbSet<Event> Events { get; set; }
  148. public DbSet<JobContact> JobContacts { get; set; }
  149. public DbSet<JobContactEvent> JobContactEvents { get; set; }
  150. public DbSet<JobContactStatusReport> JobContactStatusReports { get; set; }
  151. public DbSet<JobSensor> JobSensors { get; set; }
  152. public DbSet<JobSensorLocationPlanned> JobSensorLocationPlanned { get; set; }
  153. public DbSet<Notification> Notifications { get; set; }
  154. public DbSet<SensorData> SensorData { get; set; }
  155. public DbSet<SensorDataTemp> SensorDataTemp { get; set; }
  156. public DbSet<SensorLocation> SensorLocations { get; set; }
  157. public DbSet<Threshold> Thresholds { get; set; }
  158. public DbSet<SensorDataToday> SensorDataToday { get; set; }
  159.  
  160. }
  161.  
  162. public class ApplicationDbContextFactory : IDesignTimeDbContextFactory<ApplicationDbContext>
  163. {
  164. public ApplicationDbContext CreateDbContext(string[] args)
  165. {
  166. var optionsBuilder = new DbContextOptionsBuilder<ApplicationDbContext>();
  167. optionsBuilder.UseSqlServer("Data Source=NEWSQL\NEWSQLSERVER;Initial Catalog=RM;User ID=sa;Password=Speak2me");
  168. return new ApplicationDbContext(optionsBuilder.Options);
  169. }
  170. }
Add Comment
Please, Sign In to add comment