public IActionResult PostEmailRegistration(EmailRegistration emailRegistration) { var email = emailRegRepository.GetAll().Where(p => p.EmailAddress == emailRegistration.EmailAddress).ToList(); string postResultString; int messageNumber; if (!email.Any()) { emailRegistration.ControlCode = Guid.NewGuid().ToString(); emailRegistration.CreateTime = DateTime.Now; if (emailRegRepository.AddEmailReg(emailRegistration)) { postResultString = "E-posta listemize kaydedildiniz. Teşekkür ederiz."; messageNumber = 2; } else { postResultString = "E-posta kaydı yapılırken bir hata oluştu! Lütfen daha sonra tekrar deneyiniz."; messageNumber = 3; } } else { postResultString = "Bu e-posta adresi zaten kayıtlı!"; messageNumber = 1; } return(new JsonResult(new { message = postResultString, messageType = messageNumber })); }
public IActionResult EmailCancellation(EmailRegistration emailCancell) { var emailCancelled = emailRegRepository.GetAll().Where(p => p.EmailAddress == emailCancell.EmailAddress && p.ControlCode == emailCancell.ControlCode); if (emailCancelled.Any()) { if (ModelState.IsValid) { if (emailRegRepository.DeleteEmailReg(emailCancelled.First())) { TempData["EmailCancelledSuccess"] = "E-posta aboneliğiniz iptal edildi. Artık yeni makale yayınlandığında bildirim almayacaksınız."; } else { TempData["EmailCancelledDanger"] = "Bir hata oluştu. Lütfen daha sonra tekrar deneyiniz."; } } } else { TempData["EmailCancelledWarning"] = "Girilen e-posta adresi veya kontrol kodu için bir kayıt bulunamadı! Lütfen doğru bilgileri girdiğinizden emin olunuz."; } return(RedirectToAction("EmailCancellation")); }
private static void ValidateEmailRegistration(EmailRegistration actualEmailRegistration, string expectedEmail, string expectedRegistrationStatus, string expectedActivationCode, string expectedTenantId) { Assert.Equal(expectedEmail, actualEmailRegistration.Email); Assert.Equal(expectedRegistrationStatus, actualEmailRegistration.RegistrationStatus); Assert.Equal(expectedActivationCode, actualEmailRegistration.ActivationCode); Assert.Equal(expectedTenantId, actualEmailRegistration.TenantId); }
public bool DeleteEmailReg(EmailRegistration entity) { try { context.EmailRegistrations.Remove(entity); context.SaveChanges(); return(true); } catch { return(false); } }
public bool AddEmailReg(EmailRegistration entity) { try { context.EmailRegistrations.Add(entity); context.SaveChanges(); return(true); } catch { return(false); } }
public IActionResult GetEmailControlCode(EmailRegistration emailCancell) { string postResultString; int messageNumber; var emailCancelled = emailRegRepository.GetAll().Where(p => p.EmailAddress == emailCancell.EmailAddress); if (emailCancelled.Any()) { if (ModelState.IsValid) { var setting = settingRepository.GetById(1); string messageHtml = "" + "<div style='background-color:#F7F7F7;padding:5px;'>" + "<div style='background-color:#FFF;padding:5px;'>" + "<p>Kontrol Kodunuz: " + emailCancelled.First().ControlCode + "</p>" + "</div>" + "</div>"; MailBuilder builder = new MailBuilder(); builder.From.Add(new MailBox(setting.SMTPServerFrom, setting.SMTPServerFromName)); builder.To.Add(new MailBox(emailCancell.EmailAddress)); builder.Subject = "Abonelik İptali İçin Kontrol Kodu"; builder.Html = messageHtml; IMail email = builder.Create(); using Smtp smtp = new Smtp(); smtp.Connect(setting.SMTPServerHost, Convert.ToInt32(setting.SMTPServerPort)); // or ConnectSSL for SSL smtp.UseBestLogin(setting.SMTPServerUsername, setting.SMTPServerPassword); // remove if not needed smtp.SendMessage(email); smtp.Close(); postResultString = "Kontrol kodu, e-posta adresinize gönderildi."; messageNumber = 2; } else { postResultString = "Kontrol kodu gönderilirken bir hata oluştu! Lütfen daha sonra tekrar deneyiniz veya iletişime geçiniz."; messageNumber = 3; } } else { postResultString = "Girilen e-posta adresi için bir kayıt bulunamadı! Lütfen doğru bilgileri girdiğinizden emin olunuz."; messageNumber = 1; } return(new JsonResult(new { message = postResultString, messageType = messageNumber })); }
internal static async Task ActivateEmailAsync( DataShareManagementClient client, string location, EmailRegistration emailRegistration) { AzureOperationResponse <EmailRegistration> activateResponse = await client.EmailRegistrations.ActivateEmailWithHttpMessagesAsync( location, emailRegistration, null); EmailRegistrationScenarioTests.ValidateEmailRegistration(activateResponse.Body, "*****@*****.**", "Activated", "15ee7153fe0df5a3a449a897d6cec836", "f686d426-8d16-42db-81b7-ab578e110ccd"); Assert.Equal(HttpStatusCode.OK, activateResponse.Response.StatusCode); }
public async Task <ApplicationUser> RegisterUser(string login, string firstName, string lastName, string password, UserLoginInfo userLoginInfo) { password = string.IsNullOrEmpty(password) ? UserRegistration.GeneratePassword() : password; var provider = new EmailRegistration(this, UserManager); var user = await provider.Register(firstName, lastName, login, password, false); if (userLoginInfo != null) { await UserManager.AddLoginAsync(user.Id, userLoginInfo); } // sending not realized provider.SendConfirmation(user, password); return(user); }
/// <summary> /// Activates the tenant and email combination using email code received. /// </summary> /// <remarks> /// Activate the email registration for the current tenant /// </remarks> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='location'> /// Location of the activation. /// </param> /// <param name='emailRegistration'> /// The payload for tenant domain activation. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <EmailRegistration> ActivateEmailAsync(this IEmailRegistrationsOperations operations, string location, EmailRegistration emailRegistration, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.ActivateEmailWithHttpMessagesAsync(location, emailRegistration, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Activates the tenant and email combination using email code received. /// </summary> /// <remarks> /// Activate the email registration for the current tenant /// </remarks> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='location'> /// Location of the activation. /// </param> /// <param name='emailRegistration'> /// The payload for tenant domain activation. /// </param> public static EmailRegistration ActivateEmail(this IEmailRegistrationsOperations operations, string location, EmailRegistration emailRegistration) { return(operations.ActivateEmailAsync(location, emailRegistration).GetAwaiter().GetResult()); }
/// <summary> /// Activates the tenant and email combination using email code received. /// </summary> /// <remarks> /// Activate the email registration for the current tenant /// </remarks> /// <param name='location'> /// Location of the activation. /// </param> /// <param name='emailRegistration'> /// The payload for tenant domain activation. /// </param> /// <param name='customHeaders'> /// Headers that will be added to request. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> /// <exception cref="DataShareErrorException"> /// Thrown when the operation returned an invalid status code /// </exception> /// <exception cref="SerializationException"> /// Thrown when unable to deserialize the response /// </exception> /// <exception cref="ValidationException"> /// Thrown when a required parameter is null /// </exception> /// <exception cref="System.ArgumentNullException"> /// Thrown when a required parameter is null /// </exception> /// <return> /// A response object containing the response body and response headers. /// </return> public async Task <AzureOperationResponse <EmailRegistration> > ActivateEmailWithHttpMessagesAsync(string location, EmailRegistration emailRegistration, Dictionary <string, List <string> > customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) { if (location == null) { throw new ValidationException(ValidationRules.CannotBeNull, "location"); } if (emailRegistration == null) { throw new ValidationException(ValidationRules.CannotBeNull, "emailRegistration"); } if (Client.ApiVersion == null) { throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); } // Tracing bool _shouldTrace = ServiceClientTracing.IsEnabled; string _invocationId = null; if (_shouldTrace) { _invocationId = ServiceClientTracing.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("location", location); tracingParameters.Add("emailRegistration", emailRegistration); tracingParameters.Add("cancellationToken", cancellationToken); ServiceClientTracing.Enter(_invocationId, this, "ActivateEmail", tracingParameters); } // Construct URL var _baseUrl = Client.BaseUri.AbsoluteUri; var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "providers/Microsoft.DataShare/locations/{location}/activateEmail").ToString(); _url = _url.Replace("{location}", System.Uri.EscapeDataString(location)); List <string> _queryParameters = new List <string>(); if (Client.ApiVersion != null) { _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); } if (_queryParameters.Count > 0) { _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); } // Create HTTP transport objects var _httpRequest = new HttpRequestMessage(); HttpResponseMessage _httpResponse = null; _httpRequest.Method = new HttpMethod("POST"); _httpRequest.RequestUri = new System.Uri(_url); // Set Headers if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) { _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()); } if (Client.AcceptLanguage != null) { if (_httpRequest.Headers.Contains("accept-language")) { _httpRequest.Headers.Remove("accept-language"); } _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); } if (customHeaders != null) { foreach (var _header in customHeaders) { if (_httpRequest.Headers.Contains(_header.Key)) { _httpRequest.Headers.Remove(_header.Key); } _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); } } // Serialize Request string _requestContent = null; if (emailRegistration != null) { _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(emailRegistration, Client.SerializationSettings); _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); _httpRequest.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); } // Set Credentials if (Client.Credentials != null) { cancellationToken.ThrowIfCancellationRequested(); await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); } // Send Request if (_shouldTrace) { ServiceClientTracing.SendRequest(_invocationId, _httpRequest); } cancellationToken.ThrowIfCancellationRequested(); _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); if (_shouldTrace) { ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); } HttpStatusCode _statusCode = _httpResponse.StatusCode; cancellationToken.ThrowIfCancellationRequested(); string _responseContent = null; if ((int)_statusCode != 200) { var ex = new DataShareErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); try { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); DataShareError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject <DataShareError>(_responseContent, Client.DeserializationSettings); if (_errorBody != null) { ex.Body = _errorBody; } } catch (JsonException) { // Ignore the exception } ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); if (_shouldTrace) { ServiceClientTracing.Error(_invocationId, ex); } _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw ex; } // Create Result var _result = new AzureOperationResponse <EmailRegistration>(); _result.Request = _httpRequest; _result.Response = _httpResponse; if (_httpResponse.Headers.Contains("x-ms-request-id")) { _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); } // Deserialize Response if ((int)_statusCode == 200) { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); try { _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject <EmailRegistration>(_responseContent, Client.DeserializationSettings); } catch (JsonException ex) { _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); } } if (_shouldTrace) { ServiceClientTracing.Exit(_invocationId, _result); } return(_result); }
public async Task DataShareE2E() { Account expectedAccount = new Account(identity, "DataShareId", shareName, default(SystemData), "Microsoft.DataShare", ScenarioTestBase <DataShareE2EScenarioTests> .AccountLocation); string subscriptionIdVal = Environment.GetEnvironmentVariable(subscriptionId); Func <DataShareManagementClient, Task> action = async(client) => { await AccountScenarioTests.CreateAsync( client, this.ResourceGroupName, this.AccountName, expectedAccount); await ShareScenarioTests.CreateAsync( client, this.ResourceGroupName, this.AccountName, DataShareE2EScenarioTests.shareName, ShareScenarioTests.GetShare()); var synchronizationSetting = await SynchronizationSettingScenarioTests.CreateAsync( client, this.ResourceGroupName, this.AccountName, DataShareE2EScenarioTests.shareName, DataShareE2EScenarioTests.synchronizationSettingName, SynchronizationSettingScenarioTests.GetSynchronizationSetting()) as ScheduledSynchronizationSetting; DataSet dataSet = await DataSetScenarioTests.CreateAsync( client, this.ResourceGroupName, this.AccountName, DataShareE2EScenarioTests.shareName, DataShareE2EScenarioTests.dataSetName, DataSetScenarioTests.GetDataSet(containerName, DataSetScenarioTests.filepath, this.ResourceGroupName, ScenarioTestBase <DataShareE2EScenarioTests> .storageActName, subscriptionIdVal)); Invitation invitation = await InvitationScenarioTests.CreateAsync( client, this.ResourceGroupName, this.AccountName, DataShareE2EScenarioTests.shareName, DataShareE2EScenarioTests.invitationName, InvitationScenarioTests.GetExpectedInvitation()); EmailRegistration emailRegistration = await EmailRegistrationScenarioTests.RegisterEmailAsync(client, locationOfDatabase); await EmailRegistrationScenarioTests.ActivateEmailAsync(client, locationOfDatabase, emailRegistration); await ShareSubscriptionScenarioTests.CreateAsync( client, this.ResourceGroupName, this.AccountName, DataShareE2EScenarioTests.shareSubscriptionName, ShareSubscriptionScenarioTests.GetShareSubscription(invitation.InvitationId, DataShareE2EScenarioTests.sourceShareLocationName)); await TriggerScenarioTests.CreateAsync( client, this.ResourceGroupName, this.AccountName, DataShareE2EScenarioTests.shareSubscriptionName, DataShareE2EScenarioTests.triggerName, TriggerScenarioTests.GetTrigger( synchronizationSetting.RecurrenceInterval, synchronizationSetting.SynchronizationTime)); await DataSetMappingScenarioTests.CreateAsync( client, this.ResourceGroupName, this.AccountName, DataShareE2EScenarioTests.shareSubscriptionName, DataShareE2EScenarioTests.dataSetMappingName, DataSetMappingScenarioTests.GetDataSetMapping(containerName, DataSetScenarioTests.dataSetId, DataSetScenarioTests.filepath, this.ResourceGroupName, storageActName, subscriptionIdVal)); ShareSubscriptionScenarioTests.Synchronize( client, this.ResourceGroupName, this.AccountName, DataShareE2EScenarioTests.shareSubscriptionName); }; Func <DataShareManagementClient, Task> finallyAction = async(client) => { await AccountScenarioTests.Delete( client, this.ResourceGroupName, this.AccountName); }; await this.RunTest(action, finallyAction); }