/// <summary> /// Perform registrations and build the container - http://docs.autofac.org/en/latest/integration/csl.html /// </summary> private void ConfigureAutofac() { var builder = new ContainerBuilder(); builder.RegisterModule(new GlobalWeatherModule()); var container = builder.Build(); CoreServiceLocator.SetServiceLocator(() => new AutofacServiceLocator(container)); }
public static AuthenticationResult Authenticate(string userName, string password, out Account account, bool passwordIsHashed = false) { if (string.IsNullOrWhiteSpace(userName)) { throw new ArgumentNullException("userName"); } if (string.IsNullOrWhiteSpace(password)) { throw new ArgumentNullException("password"); } int authenticationAttemptID = 0; AuthenticationStatus result = AuthenticationStatus.Failure_Unknown; using (ICoreRepositoryManager repository = CoreServiceLocator.GetRepositoryManager()) { CoreEntities ctx = repository.DataModel; account = null; //lets patch up the username and remove any leading or trailing spaces. userName = userName.Trim(); //lets look and see if the userName is an email address. account = ctx.Accounts.SingleOrDefault(p => p.UserName == userName && !p.Voided); if (account != null) { //check account approved/disabled result = account.Approved ? AuthenticationStatus.Success : AuthenticationStatus.Failure_AccountNotApproved; result = account.Disabled ? AuthenticationStatus.Failure_AccountDisabled : AuthenticationStatus.Success; result = account.Password == null ? AuthenticationStatus.Failure_NoPassword : AuthenticationStatus.Success; //if so far we are approved and not disabled, and password is not null, then lets check the password against the input. if (result == AuthenticationStatus.Success && !VerifyPasswordMatch(password, account.Password, passwordIsHashed)) { result = AuthenticationStatus.Failure_IncorrectPassword; } } else { result = AuthenticationStatus.Failure_AccountNotExist; } if (account != null) { //detach the contact so we don't have to worry about duplicates being committed into the database since this context is going out of scope *very* soon. ctx.Detach(account); } } return(new AuthenticationResult(result, authenticationAttemptID)); }
//TODO make this more generic between different methods? Sync, Publish, etc. private static async Task <int> RunSyncWithOptionsAndExit(SyncOptions syncOptions) { var locator = new CoreServiceLocator(); ITaskReportable <SyncData> syncService = locator.GetService <SyncService>(); IReport report = await syncService.StartTask(syncOptions.ToSyncData()).ConfigureAwait(true); Console.WriteLine(report); if (report.Success) { return(0); } return(1); }