public void SendImpl(string name, long mobile, string body, params string[] args) { SmsProvider provider = SmsProvider.Create(name); M.Sms sms = M.Sms.GetById(DataSource, provider.Key); if (!sms.Enabled) { throw new Exception(); } provider.Account = sms.Account; provider.Token = sms.Token; provider.AppId = sms.AppId; provider.Log = new SmsSqlLog(DataSource); provider.Send(mobile, body, args); }
public BaseResponse Auth(User user) { var loginType = user.LoginType; Random rnd = new Random(); int randomNumber = rnd.Next(100000, 999999); try { switch (loginType) { case LoginType.Email: var toEmail = user.Login; EmailService.SendEmailAsync(toEmail, "Cleanly код активации", randomNumber.ToString()); break; case LoginType.Phone: SmsProvider.Send(null, user.Login, randomNumber.ToString()); break; } } catch (System.Exception ex) { if (ex.InnerException is System.IO.IOException) { } } ActivationCode code = new ActivationCode { User = user, Created = DateTime.UtcNow, Code = randomNumber.ToString() }; DbContext.ActivationCodes.Add(code); DbContext.SaveChanges(); return(new BaseResponse()); }
public BaseResponse Register(string login, LoginType loginType) { Random rnd = new Random(); int randomNumber = rnd.Next(100000, 999999); try { switch (loginType) { case LoginType.Email: var toEmail = login; EmailService.SendEmailAsync(toEmail, "Cleanly код активации", randomNumber.ToString()); break; case LoginType.Phone: SmsProvider.Send(null, login, randomNumber.ToString()); break; } } catch (System.Exception ex) { if (ex.InnerException is System.IO.IOException) { } } var user = new User() { LoginType = loginType, Login = login, Created = DateTime.UtcNow }; DbContext.Users.Add(user); DbContext.SaveChanges(); var person = new Person() { UserId = user.Id }; switch (loginType) { case LoginType.Email: person.Email = login; break; case LoginType.Phone: person.Phone = login; break; } DbContext.Persons.Add(person); DbContext.SaveChanges(); ActivationCode code = new ActivationCode { User = user, Created = DateTime.UtcNow, Code = randomNumber.ToString() }; DbContext.ActivationCodes.Add(code); DbContext.SaveChanges(); return(new BaseResponse()); }