public async Task <ActionResult> PostVerifyUserEmailAddress([FromBody] UserEmailRequest userEmailRequest)
        {
            var dbTransaction = await _dataContext.Database.BeginTransactionAsync();

            var result = await _authRepository.VerifyUserEmailAddress(userEmailRequest, _configuration.GetValue <string>("AppSettings:Secret"));

            if (result.StatusCode == Utils.Success)
            {
                var userDetails      = (UserDetails)result.ObjectValue;
                var userInfoToReturn = _mapper.Map <UserLoginResponse>(userDetails);
                if (userDetails.User.UserType == Utils.Customer)
                {
                    //CUSTOMER
                    userInfoToReturn.UserProfileInformation = _mapper.Map <CustomerResponse>((Customer)userDetails.userProfile);
                }
                else
                {
                    //ADMINISTRATOR
                    userInfoToReturn.UserProfileInformation = _mapper.Map <AdministratorResponse>((Administrator)userDetails.userProfile);
                }

                result.ObjectValue = userInfoToReturn;
                await dbTransaction.CommitAsync();

                return(StatusCode(StatusCodes.Status200OK, result));
            }
            else
            {
                await dbTransaction.RollbackAsync();

                return(StatusCode(StatusCodes.Status400BadRequest, result));
            }
        }
        public async Task <IActionResult> GetUserByEmail([FromBody] UserEmailRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(this.BadRequest(new Response
                {
                    IsSuccess = false,
                    Message = "Bad request"
                }));
            }

            var user = await this.userHelper.GetUserByEmailAsync(request.Email);

            return(user == null
                ? (IActionResult)this.BadRequest(new Response
            {
                IsSuccess = false,
                Message = "User don't exists."
            })
                : Ok(user));
        }
 /// <summary>
 /// Invites a new or existing user to an app
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='ownerName'>
 /// The name of the owner
 /// </param>
 /// <param name='appName'>
 /// The name of the application
 /// </param>
 /// <param name='userEmail'>
 /// The email of the user to invite
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task CreateAsync(this IAppInvitations operations, string ownerName, string appName, UserEmailRequest userEmail = default(UserEmailRequest), CancellationToken cancellationToken = default(CancellationToken))
 {
     (await operations.CreateWithHttpMessagesAsync(ownerName, appName, userEmail, null, cancellationToken).ConfigureAwait(false)).Dispose();
 }
 /// <summary>
 /// Invites a new or existing user to an app
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='ownerName'>
 /// The name of the owner
 /// </param>
 /// <param name='appName'>
 /// The name of the application
 /// </param>
 /// <param name='userEmail'>
 /// The email of the user to invite
 /// </param>
 public static void Create(this IAppInvitations operations, string ownerName, string appName, UserEmailRequest userEmail = default(UserEmailRequest))
 {
     operations.CreateAsync(ownerName, appName, userEmail).GetAwaiter().GetResult();
 }
Beispiel #5
0
        public async Task <ReturnResponse> VerifyUserEmailAddress(UserEmailRequest userEmailRequest, string secretKey)
        {
            try
            {
                //FIRST OF ALL CONFIRM EMAIL TOKEN BEFORE USING IT TO GET USER DETAILS
                //Continue
                bool emailTokenConfirmed;
                //NO LOGIN REQUIRED TO CONFIRM EMAIL SO...
                //string userEmail = Encoding.UTF8.GetString(Convert.FromBase64String(userEmailRequest.EmailConfirmationLinkToken.Replace("ngiSlauqe", "=")));
                userEmailRequest.EmailConfirmationLinkToken = userEmailRequest.EmailConfirmationLinkToken.Replace('-', '%');
                var      originalUserToken    = Uri.UnescapeDataString(userEmailRequest.EmailConfirmationLinkToken);
                string[] emailTokenVal        = originalUserToken.Split('#', 2);
                string   userEmailTokenBase64 = "";
                string   userEmailBase64      = "";
                if (emailTokenVal.Length == 1)
                {
                    userEmailTokenBase64 = emailTokenVal[0];
                }
                else
                {
                    userEmailTokenBase64 = emailTokenVal[0];
                    userEmailBase64      = emailTokenVal[1];
                }

                string userEmail = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(userEmailBase64));
                var    user      = await _userManager.FindByEmailAsync(userEmail);

                if (user != null)
                {
                    if (user.EmailConfirmed)
                    {
                        //EMAIL ALREADY CONFIRMED
                        return(new ReturnResponse()
                        {
                            StatusCode = Utils.EmailAlreadyConfirmed,
                            StatusMessage = Utils.StatusMessageEmailAlreadyConfirmed
                        });
                    }
                    else
                    {
                        IdentityResult identityResult = await _userManager.ConfirmEmailAsync(user, userEmailTokenBase64);

                        if (identityResult.Succeeded)
                        {
                            emailTokenConfirmed = true;
                        }
                        else
                        {
                            emailTokenConfirmed = false;
                        }

                        if (emailTokenConfirmed)
                        {
                            //AFTER EMAIL CONFIRMATION AUTOMATICALLY LOG THE USER IN
                            //var appUser = await _userManager.Users.FirstOrDefaultAsync(c => c.NormalizedEmail == user.Email.ToUpper());
                            if ((user.UserType == Utils.Customer) || (user.UserType == Utils.Administrator))
                            {
                                //CUSTOMER OR ADMINISTRATOR
                                //AFTER EMAIL CONFIRMATION AUTOMATICALLY LOG THE USER IN
                                var loginResult = await LogUserInWithoutPassword(user);

                                if (loginResult.StatusCode == Utils.Success)
                                {
                                    return(loginResult);
                                }
                                else
                                {
                                    return(loginResult);
                                }
                            }
                            else
                            {
                                //INVALID USERTYPE
                                return(new ReturnResponse()
                                {
                                    StatusCode = Utils.InvalidUserType,
                                    StatusMessage = Utils.StatusMessageInvalidUserType
                                });
                            }
                        }
                        else
                        {
                            return(new ReturnResponse()
                            {
                                StatusCode = Utils.NotSucceeded,
                                StatusMessage = Utils.StatusMessageNotSucceeded
                            });
                        }
                    }
                }
                else
                {
                    return(new ReturnResponse()
                    {
                        StatusCode = Utils.NotFound,
                        StatusMessage = Utils.StatusMessageNotFound
                    });
                }
            }
            catch (NullReferenceException)
            {
                return(new ReturnResponse()
                {
                    StatusCode = Utils.NotSucceeded,
                    StatusMessage = Utils.StatusMessageNotSucceeded
                });
            }
        }
        /// <summary>
        /// Invites a new or existing user to an app
        /// </summary>
        /// <param name='ownerName'>
        /// The name of the owner
        /// </param>
        /// <param name='appName'>
        /// The name of the application
        /// </param>
        /// <param name='userEmail'>
        /// The email of the user to invite
        /// </param>
        /// <param name='customHeaders'>
        /// Headers that will be added to request.
        /// </param>
        /// <param name='cancellationToken'>
        /// The cancellation token.
        /// </param>
        /// <exception cref="ErrorResponseException">
        /// Thrown when the operation returned an invalid status code
        /// </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 <HttpOperationResponse> CreateWithHttpMessagesAsync(string ownerName, string appName, UserEmailRequest userEmail = default(UserEmailRequest), Dictionary <string, List <string> > customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (ownerName == null)
            {
                throw new ValidationException(ValidationRules.CannotBeNull, "ownerName");
            }
            if (appName == null)
            {
                throw new ValidationException(ValidationRules.CannotBeNull, "appName");
            }
            if (userEmail != null)
            {
                userEmail.Validate();
            }
            // Tracing
            bool   _shouldTrace  = ServiceClientTracing.IsEnabled;
            string _invocationId = null;

            if (_shouldTrace)
            {
                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("ownerName", ownerName);
                tracingParameters.Add("appName", appName);
                tracingParameters.Add("userEmail", userEmail);
                tracingParameters.Add("cancellationToken", cancellationToken);
                ServiceClientTracing.Enter(_invocationId, this, "Create", tracingParameters);
            }
            // Construct URL
            var _baseUrl = Client.BaseUri.AbsoluteUri;
            var _url     = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "v0.1/apps/{owner_name}/{app_name}/invitations").ToString();

            _url = _url.Replace("{owner_name}", System.Uri.EscapeDataString(ownerName));
            _url = _url.Replace("{app_name}", System.Uri.EscapeDataString(appName));
            // 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 (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 (userEmail != null)
            {
                _requestContent      = Microsoft.Rest.Serialization.SafeJsonConvert.SerializeObject(userEmail, 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 != 204)
            {
                var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
                try
                {
                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                    ErrorResponse _errorBody = Microsoft.Rest.Serialization.SafeJsonConvert.DeserializeObject <ErrorResponse>(_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 HttpOperationResponse();

            _result.Request  = _httpRequest;
            _result.Response = _httpResponse;
            if (_shouldTrace)
            {
                ServiceClientTracing.Exit(_invocationId, _result);
            }
            return(_result);
        }
 /// <summary>
 /// Adds a new user to a team that is owned by an organization
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='orgName'>
 /// The organization's name
 /// </param>
 /// <param name='teamName'>
 /// The team's name
 /// </param>
 /// <param name='userEmail'>
 /// The email of the user to add to the team
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <TeamUserResponse> AddUserAsync(this ITeams operations, string orgName, string teamName, UserEmailRequest userEmail = default(UserEmailRequest), CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.AddUserWithHttpMessagesAsync(orgName, teamName, userEmail, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
 /// <summary>
 /// Adds a new user to a team that is owned by an organization
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='orgName'>
 /// The organization's name
 /// </param>
 /// <param name='teamName'>
 /// The team's name
 /// </param>
 /// <param name='userEmail'>
 /// The email of the user to add to the team
 /// </param>
 public static TeamUserResponse AddUser(this ITeams operations, string orgName, string teamName, UserEmailRequest userEmail = default(UserEmailRequest))
 {
     return(operations.AddUserAsync(orgName, teamName, userEmail).GetAwaiter().GetResult());
 }
Beispiel #9
0
 /// <summary>
 /// Removes a user's invitation to an organization
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='orgName'>
 /// The organization's name
 /// </param>
 /// <param name='userEmail'>
 /// The email of the user whose invitation should be removed
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task DeleteAsync(this IOrgInvitations operations, string orgName, UserEmailRequest userEmail = default(UserEmailRequest), CancellationToken cancellationToken = default(CancellationToken))
 {
     (await operations.DeleteWithHttpMessagesAsync(orgName, userEmail, null, cancellationToken).ConfigureAwait(false)).Dispose();
 }
Beispiel #10
0
 /// <summary>
 /// Removes a user's invitation to an organization
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='orgName'>
 /// The organization's name
 /// </param>
 /// <param name='userEmail'>
 /// The email of the user whose invitation should be removed
 /// </param>
 public static void Delete(this IOrgInvitations operations, string orgName, UserEmailRequest userEmail = default(UserEmailRequest))
 {
     operations.DeleteAsync(orgName, userEmail).GetAwaiter().GetResult();
 }