Exemplo n.º 1
0
        public async Task <Result <LoginResponse> > SignInAsync(CreateLoginRequest loginRequest)
        {
            try
            {
                StringContent       content  = new StringContent(JsonConvert.SerializeObject(loginRequest), System.Text.Encoding.UTF8, "application/json");
                HttpResponseMessage response = await _client.PostAsync("api/Login", content);

                response.EnsureSuccessStatusCode();

                var responseContent = response.Content;

                var strObj = await responseContent.ReadAsStringAsync();

                var loginResponse = JsonConvert.DeserializeObject <Result <LoginResponse> >(strObj);
                if (!loginResponse.ValidOperation)
                {
                    return(loginResponse);
                }

                await _localStorage.SetItemAsync("authToken", loginResponse.Value.Token);

                await _localStorage.SetItemAsync("authRefreshToken", loginResponse.Value.RefreshToken);

                ((BaseApiAuthenticationStateProvider)_authenticationStateProvider).MarkUserAuthenticated(loginResponse.Value.Token);
                //_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", loginResult.Token);

                return(loginResponse);
            }
            catch (Exception ex)
            {
                return(new Result <LoginResponse> {
                    ValidOperation = false, Message = ex.Message
                });
            }
        }
Exemplo n.º 2
0
        public async Task<HttpResponseMessage> Create([FromBody] LoginDto login)
        {
            var request = new CreateLoginRequest()
            {
                User = login
            };

            UserDto loggedUser = await _mediator.ExecuteAsync(request).ConfigureAwait(false);
            return Request.CreateResponse(System.Net.HttpStatusCode.Created, new { id = loggedUser.Id, authToken = loggedUser.AuthToken });
        }
        public async Task <IActionResult> CreateLogin(CreateLoginRequest request)
        {
            var response = await _authService.TryCreateLogin(request.Username, request.Password);

            if (response.Success)
            {
                return(Ok(new LoginResponse()
                {
                    Username = request.Username
                }));
            }
            else
            {
                return(BadRequest(response));
            }
        }
Exemplo n.º 4
0
        public BaseResponse CreateLogin(string memberId, string userName, string initialPassword, string postalCode)
        {
            methodName = "CreateLogin";

            List <Message> errors    = new List <Message>();
            string         errortext = string.Empty;

            try
            {
                #region validate input
                // All params are required
                if ((memberId.Trim() == "") ||
                    (userName.Trim() == "") ||
                    (initialPassword.Trim() == "") ||
                    (postalCode.Trim() == ""))
                {
                    errors.Add(new Message("ImproperValidationCriteriaException"));
                }
                using (HarperLINQ.AHT_MainDataContext context = new AHT_MainDataContext(ConfigurationManager.ConnectionStrings["AHT_MainConnectionString"].ConnectionString))
                {
                    string exception = string.Empty;
                    bool   exists    = false;
                    int    existing  = (from a in context.tbl_Customers
                                        join b in context.SFG_CustomerNumbers
                                        on a.cusID equals b.cusID
                                        where a.cusUserName == userName.Trim() &&
                                        b.SFGCustNum != memberId.Trim()
                                        select a).Count();
                    if (existing > 0)
                    {
                        exists    = true;
                        exception = "User name is in use.";
                    }
                    existing = 0;
                    existing = (from a in context.tbl_Customers
                                join b in context.SFG_CustomerNumbers
                                on a.cusID equals b.cusID
                                where a.cusDisplayName == userName.Trim() &&
                                b.SFGCustNum != memberId.Trim()
                                select a).Count();
                    if (existing > 0)
                    {
                        exists     = true;
                        exception += "  Screen name is in use.";
                    }
                    existing = 0;
                    existing = (from a in context.tbl_Customers
                                join b in context.SFG_CustomerNumbers
                                on a.cusID equals b.cusID
                                where a.cusEmail == userName.Trim() &&
                                b.SFGCustNum != memberId.Trim()
                                select a).Count();
                    if (existing > 0)
                    {
                        exists     = true;
                        exception += "Email address is in use.";
                    }
                    if (exists)
                    {
                        throw new Exception(exception);
                    }
                }
                #endregion

                CreateLoginRequest request = new CreateLoginRequest(memberId.Trim(), userName.Trim(), initialPassword.Trim(), postalCode.Trim(), false);
                baseResponse = UserMaintenance.CreateLogin(request);
                if (baseResponse != null &&
                    baseResponse.TypedResponse != null &&
                    baseResponse.TypedResponse.GetType().Name == "CreateLoginResponse" &&
                    (baseResponse.TypedResponse as CreateLoginResponse).Success)
                {
                    HarperACL.Authenticator auth = new Authenticator(userName.Trim(), Cryptography.Hash(initialPassword.Trim(), true), true, true, false, memberId.Trim());
                    if (!auth.CreateUsername(userName.Trim(), initialPassword.Trim(), memberId.Trim()))
                    {
                        throw new Exception("User created at SFG, could not create user at AH");
                    }
                }
            }
            catch (Exception ex)
            {
                errortext = string.Format("Error creating login. Memberid: {0} Username: {1} Password: {2} PostalCode: {3} \r\nException message: {4}\r\nException stacktrace: {5}", new object[] { memberId, userName, initialPassword, postalCode, ex.Message, ex.StackTrace });
                errors.Add(new Message(MessageSources.AndrewHarper, 0, "CreateLoginException", errortext, "", "", null));
            }
            foreach (Message error in errors)
            {
                if (baseResponse == null)
                {
                    baseResponse = new BaseResponse();
                }
                baseResponse.Messages.Add(error);

                StringBuilder error_text = new StringBuilder();
                error_text.AppendLine("CREATELOGIN ERROR LOGGED");
                error_text.AppendLine(string.Format("MEMBERID {0}", memberId));
                baseResponse.Messages.Add(error);
                error_text.AppendLine(string.Format("ERROR: {0}", new object[] { error.AhMessage }));
                EventLogger.LogError("MembershipLogic.CreateLogin", error_text.ToString(), true);
            }

            return(baseResponse);
        }
Exemplo n.º 5
0
 public static BaseResponse CreateLogin(CreateLoginRequest ahRequest)
 {
     return(GetResponse(Methods.CREATELOGIN, ahRequest));
 }