コード例 #1
0
ファイル: UserBusiness.cs プロジェクト: Batonja/Projekat
        public Holder <User> SignUp(User user)
        {
            User userFromDb = _userDatabase.GetUserByPassportId(user.PassportId);

            if (userFromDb != null)
            {
                return(CheckUser(user, 400, "User with this passport is already registered"));
            }


            List <User> usersFromDb = new List <User>();

            usersFromDb = _userDatabase.GetUsers();


            foreach (var userDb in usersFromDb)
            {
                if (String.Compare(userDb.Email, user.Email) == 0)
                {
                    return(CheckUser(user, 400, "User with this email already exists"));
                }
            }



            string[] encryptedUserPassword = PasswordHelper.EncryptPassword(user.Key);
            string   safePassword          = PasswordHelper.GetMeAString(encryptedUserPassword[1]);
            string   salt = PasswordHelper.GetMeAString(encryptedUserPassword[0]);

            user.Key  = safePassword;
            user.Salt = salt;



            return(_userDatabase.SignUp(user) ? CheckUser(user, 200, "") : CheckUser(user, 400, "Unable to register user"));
        }
コード例 #2
0
        async void ExecuteToMainPage()
        {
            userDatabase = new UserDatabase();
            var users = await userDatabase.GetUsers();

            var user = await userDatabase.GetUserByEmail(Login.Email);


            if (user != null)
            {
                var logInfo = new { Email = user.Email, Password = user.Password };

                var json    = JsonConvert.SerializeObject(logInfo);
                var uri     = "http://10.0.2.2:5000/UserLoginDetails";
                var content = new StringContent(json, System.Text.Encoding.UTF8, "application/json");
                var http    = new HttpClient();
                await NavigationService.NavigateAsync("MainPage");

                var post = await http.PostAsync(uri, content);

                try
                {
                    await _pageDialog.DisplayAlertAsync("Hey There", post.ReasonPhrase, "Okay");
                }
                catch (Exception ex)
                {
                    await _pageDialog.DisplayAlertAsync("Hey There", ex.Message, "Ok");
                }
            }
            else
            {
                await _pageDialog.DisplayAlertAsync("Hey There", "Current User doesn't exist", "Ok");

                Login = new Login();
            }
        }
コード例 #3
0
 public async override void Initialize(INavigationParameters parameters)
 {
     userDatabase = new UserDatabase();
     var users = await userDatabase.GetUsers();
 }