Пример #1
0
        public static void LogIn()
        {
            if (token == null)
            {
                string username, password;
                Console.Write("Username:"******"Password:"******"--> Logged In! <--");
                }
                catch (FaultException ex)
                {
                    token = null;
                    Console.WriteLine($"--> {ex.Message} <--");
                }
            }
            else
            {
                Console.WriteLine("--> Already Logged In! <--");
            }
        }
        public async Task <string> AuthenticateAsync(LogInCredentials user)
        {
            var userJson      = JsonConvert.SerializeObject(user);
            var userPostReady = new HttpStringContent(userJson, Windows.Storage.Streams.UnicodeEncoding.Utf8, "application/json");

            var response = await _httpClient.PostAsync(new Uri(_apiUrl + "/authenticate"), userPostReady);

            if (response.IsSuccessStatusCode)
            {
                var loginResponse = JsonConvert.DeserializeObject <LoginResponse>(await response.Content.ReadAsStringAsync());
                await StorageService.StoreUserToken(loginResponse.Token);

                await StorageService.StoreUserId(loginResponse.UserId);

                UserResponse uType = await GetUser();

                StorageService.UserType = (int)uType.UserType;
                if ((int)uType.UserType == 0)
                {
                    NavigationRoot.Instance.IsOwner = true;
                }
                else
                {
                    NavigationRoot.Instance.IsOwner = false;
                }
                return("Succesvol ingelogd");
            }
            else
            {
                return(response.Content.ToString());
            }
        }
        public User Post([FromBody] LogInCredentials SuppliedCredentials)
        {
            var _user = _userService.GetUserByUsername(SuppliedCredentials.Username);

            if (_user == null)
            {
                return(null);
            }
            else
            {
                var actualCredentials = new LogInCredentials();

                actualCredentials.Username = _user.UserName;
                actualCredentials.Password = _user.Password;


                //bool _isAuthenticCredentials = _userService.ValidateCredentials(SuppliedCredentials, actualCredentials);
                bool _isAuthenticCredentials = false;

                if (!_isAuthenticCredentials)
                {
                    return(null);
                }

                return(_user);
            }
        }
Пример #4
0
 public string LogIn(LogInCredentials credentials)
 {
     if (repo.LogIn(credentials))
     {
         return(repo.GenerateToken(credentials.Username));
     }
     throw new FaultException("Authentication Failed!");
 }
Пример #5
0
        public UserHasAccess Login(LogInCredentials oUser)
        {
            var user = Global.Users.SingleOrDefault(u => u.UserName == oUser.Username);

            bool isValidPassword = BCrypt.Net.BCrypt.Verify(oUser.Password, user.Password);

            if (isValidPassword)
            {
                SetIsLoggedIn(user);
                User          _user          = GetUserByUsername(oUser.Username);
                UserHasAccess _userHasAccess = GetUserAccessByUserId(_user.Id);
                return(_userHasAccess);
            }
            return(null);
        }
Пример #6
0
        public bool LogIn(LogInCredentials credentials)
        {
            var user = context.Products.SingleOrDefault(x => x.Username == credentials.Username);

            if (user != null)
            {
                if (user.PasswordHash == credentials.Password)
                {
                    user.IsAuth = true;
                    context.SaveChanges();
                    return(true);
                }
                return(false);
            }
            return(false);
        }
        public Person Select(LogInCredentials value)
        {
            try
            {
                this.cmd.CommandText = @"select top 1 * from Person where Password = @pw and Email = @mail";
                this.cmd.Parameters.AddWithValue("@pw", value.Password);
                this.cmd.Parameters.AddWithValue("@mail", value.Mail);

                this.conn.Open();
                if (this.conn.State.Equals(ConnectionState.Open))
                {
                    this.read = this.cmd.ExecuteReader();
                    if (this.read.Read())
                    {
                        return(new Person(
                                   this.read.GetInt32(0),
                                   this.Check(this.read.GetString(1)),
                                   this.Check(this.read.GetString(2)),
                                   this.read.GetDateTime(3),
                                   this.read.GetDouble(4),
                                   this.read.GetDouble(5),
                                   this.Check(this.read.GetString(6)),
                                   this.read.GetDateTime(7),
                                   this.Check(this.read.GetString(8)),
                                   this.read.GetInt32(9)
                                   ));
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    throw new Exception("Connection is not open.");
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("\n\n" + e.Message + "\n\n");
                return(null);
            }
            finally { this.EndQuery(); }
        }
        // Imagine we have a button on the Companies.xaml with a redirection to another page
        // Then:
        // Task NavigateToWhateverPageAsync() {_navigatinService.NavigateToWhateverPage()}
        // Awesome isn't it?
        private async void LogIn(LogInCredentials c)
        {
            var result = await _userService.AuthenticateAsync(c);

            if (result == "Succesvol ingelogd")
            {
                if (StorageService.UserType == 0)
                {
                    await _navigationService.NavigateToAccountAsync();
                }
                else
                {
                    await _navigationService.NavigateToCompaniesAsync();
                }
            }
            else
            {
                ErrorText = "Incorrecte inloggegevens.";
            }
        }
 public IHttpActionResult Post([FromBody] LogInCredentials value)
 {
     return(Json(new LogInCredentialsDataAccessController().Select(value)));
 }
        public UserHasAccess Login([FromBody] LogInCredentials oUser)
        {
            UserHasAccess _user = _userService.Login(oUser);

            return(_user);
        }