Esempio n. 1
0
        /// <summary>
        /// Registers an account and goes to the actions view if successful
        /// </summary>
        private async void RegisterAccount()
        {
            bool isEmailValid = (Regex.IsMatch(email, @"^(?("")("".+?(?<!\\)""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))" +
                                               @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-\w]*[0-9a-z]*\.)+[a-z0-9][\-a-z0-9]{0,22}[a-z0-9]))$", RegexOptions.IgnoreCase, TimeSpan.FromMilliseconds(250)));

            bool isPasswordValid = (Regex.IsMatch(password, @"^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$", RegexOptions.IgnoreCase, TimeSpan.FromMilliseconds(250)));

            if (isEmailValid && isPasswordValid && !String.IsNullOrEmpty(username))
            {
                User user = new User {
                    userName = username, psw = password, email = email
                };
                User addedUser = serverClient.AddUser(user);
                if (addedUser != null)
                {
                    sharedData.LoggedInUser = addedUser;
                    ((MasterDetailPage)Application.Current.MainPage).IsGestureEnabled = true;
                    await NavigationService.NavigateToAsync(typeof(ActionsViewModel));
                }
                else
                {
                    UserNameErrorVisibile = true;
                }
            }
        }