コード例 #1
0
        async void DoCreateAccountCommand()
        {
            User user = new User {
                email = Email, username = Username, password = EncryptionService.encrypt(Password), name = Name, lastname = Lastname, image_url = UserImageUrl, created_at = DateTime.Now, updated_at = DateTime.Now
            };

            try
            {
                OperationResult result = await _mLearningService.CreateAccount <User>(user, (usr) => usr.id, _selectedUserType);

                SessionService.LogIn(result.id, Username);

                SharedPreferences prefs = Constants.GetSharedPreferences(Constants.PreferencesFileName);
                prefs.PutString(Constants.UserFirstNameKey, Name);
                prefs.PutString(Constants.UserLastNameKey, Lastname);
                prefs.PutString(Constants.UserImageUrlKey, UserImageUrl);

                prefs.Commit();


                ClearProperties();
                ShowViewModel <MainViewModel>();
                RegistrationOK = true;
            }
            catch (WebException e)
            {
                ConnectionOK = false;
            }
            catch (MobileServiceInvalidOperationException ex)
            {
                OperationOK = false;
            }
        }
コード例 #2
0
        async void DoRegisterCommand1()
        {
            try
            {
                MLearningDB.User newuser = new MLearningDB.User {
                    email = Email, username = RegUsername, password = EncryptionService.encrypt(RegPassword), name = Name, lastname = ":)", image_url = "http://www.clinicatorielli.com/img/icons/no-user.png", created_at = DateTime.Now, updated_at = DateTime.Now
                };


                int idInstitution = 1;
                newuser.password = EncryptionService.encrypt(newuser.password);
                bool exists = await _mLearningService.CheckIfExistsNoLocale <MLearningDB.User>
                                  (usr => usr.username == newuser.username, (it) => it.updated_at, it => it.id);

                if (exists)
                {
                    return;
                }

                OperationResult op = await _mLearningService.CreateAndRegisterConsumer(newuser, idInstitution);

                MLearningDB.User user = new MLearningDB.User {
                    username = newuser.username, password = newuser.password
                };

                SharedPreferences prefs = Constants.GetSharedPreferences(Constants.PreferencesFileName);
                prefs.PutString(Constants.UserFirstNameKey, Name);
                prefs.PutString(Constants.UserLastNameKey, Lastname);
                prefs.PutString(Constants.UserImageUrlKey, UserImageUrl);

                prefs.Commit();

                ClearProperties();

                ShowViewModel <MainViewModel>();
            }
            catch (MobileServiceInvalidOperationException e) {
                ConnectionOK = false;
            }
            catch (WebException e)
            {
                ConnectionOK = false;
            }
        }
コード例 #3
0
        async void DoLoginCommand()
        {
            StatusLabel = _waitingMessage;

            ////Populate

            //var users = Builder<MLearningDB.User>.CreateListOfSize(5000).All().With(x => x.id = 0 ).And(x=>x.created_at = DateTime.UtcNow).And(x=>x.updated_at = DateTime.UtcNow).And(x=>x.social_id=null).Build();

            //foreach (var user in users)
            //{
            //    await _mLearningService.CreateAccount<MLearningDB.User>(user, u => u.id, UserType.Consumer);

            //    _mLearningService.AddUserToCircle(user.id, 45);
            //}



            ////end populate



            try
            {
                User user = new User {
                    username = Username, password = EncryptionService.encrypt(Password)
                };
                //   User user = new User { username = Username, password = Password };
                LoginOperationResult <User> result = await _mLearningService.ValidateLogin <User>(user, u => u.password == user.password && u.username == user.username, u => u.id, u => u.type);

                // LoginOperationResult result = await _mLearningService.ValidateConsumerLogin(user.username,user.password);

                if (result.successful)
                {
                    LoginOK = true;
                    SessionService.LogIn(result.id, Username);

                    SharedPreferences prefs = Constants.GetSharedPreferences(Constants.PreferencesFileName);
                    prefs.PutString(Constants.UserFirstNameKey, result.account.name);
                    prefs.PutString(Constants.UserLastNameKey, result.account.lastname);
                    prefs.PutString(Constants.UserImageUrlKey, result.account.image_url);

                    prefs.Commit();


                    switch ((UserType)result.userType)
                    {
                    case UserType.Consumer:

                        //Select corresponding user screen

                        ShowViewModel <MainViewModel>();


                        break;

                                                #if (ADMIN)
                    case UserType.Head:


                        ShowViewModel <HeadMainViewModel>(new { user_id = result.id });

                        break;

                    case UserType.Publisher:

                        ShowViewModel <PublisherMainViewModel>(new { user_id = result.id });
                        break;
                                                #endif

                    default:
                        StatusLabel = _wrongCredentialsMessage;
                        LoginOK     = false;
                        break;
                    }
                }
                else
                {
                    StatusLabel = _wrongCredentialsMessage;
                    LoginOK     = false;
                }
            }
            catch (WebException e)
            {
                StatusLabel  = _noInternetMessage;
                ConnectionOK = false;
            }
            catch (HttpRequestException e)
            {
                StatusLabel  = _noInternetMessage;
                ConnectionOK = false;
            }
            catch (MobileServiceInvalidOperationException e)
            {
                Mvx.Trace("MobileServiceInvalidOperationException " + e.Message);
                OperationOK = false;
            }
        }