Esempio n. 1
0
        Task IUserTokenProvider <BackOfficeIdentityUser, int> .NotifyAsync(string token, UserManager <BackOfficeIdentityUser, int> manager, BackOfficeIdentityUser user)
        {
            var db      = new FortressDatabase();
            var details = db.GetUserDetails(user.Id);

            var settings = db.GetSettingsFromDatabase();

            if (details == null || !details.IsValidated || details.Provider == "SMS")
            {
                details.CurrentCode          = token;
                details.CurrentCodeGenerated = DateTime.UtcNow;
                db.Update(details);
            }
            var SmsProvider = FortressContext.GetCurrentSmsProvider();

            SmsProvider.SendSms(details.Configuration, string.Format(settings.SMS_MessageFormat, token));
            return(Task.FromResult(true));
        }
        public HttpResponseMessage SetupSMS(string number)
        {
            var user    = SignInManager.GetVerifiedUserId();
            var details = CustomDatabase.GetUserDetails(user);

            if (details != null && details.IsValidated)
            {
                throw new UnauthorizedAccessException("This account has already setup SMS");
            }
            var isNew = details == null;

            details               = new FortressUser2FASettings();
            details.UserId        = user;
            details.Provider      = "SMS";
            details.Configuration = number;
            details.IsValidated   = false;

            lock (syncLock)
            {
                var code = _random.Next(999999).ToString();
                details.CurrentCode          = code;
                details.CurrentCodeGenerated = DateTime.UtcNow;
            }

            if (isNew)
            {
                CustomDatabase.Insert(details);
            }
            else
            {
                CustomDatabase.Update(details);
            }
            var settings    = CustomDatabase.GetSettingsFromDatabase();
            var SmsProvider = FortressContext.GetCurrentSmsProvider();

            SmsProvider.SendSms(details.Configuration, string.Format(settings.SMS_MessageFormat, details.CurrentCode));

            var response = Request.CreateResponse(HttpStatusCode.OK, new { token = "123456" });

            return(response);
        }