Пример #1
0
 public void SaveCacheUserInfo(User user)
 {
     ISharedPreferences pref = Application.Context.GetSharedPreferences("UserInfo", FileCreationMode.Private);
     ISharedPreferencesEditor edit = pref.Edit();
     edit.PutString("Id", user.Id.ToString());
     edit.PutString("Email", user.Email);
     edit.PutString("Password", user.Password);
     edit.PutString("AuthKey", user.AuthKey);
     edit.Commit();
 }
Пример #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.register);
            btnRegister = FindViewById<Button>(Resource.Id.btnRegister);
            txtPassword = FindViewById<EditText>(Resource.Id.txtPassword);
            txtEmail = FindViewById<EditText>(Resource.Id.txtEmail);
            txtFirstName = FindViewById<EditText>(Resource.Id.txtFirstName);
            txtLastName = FindViewById<EditText>(Resource.Id.txtLastName);
            btnRegister.Click += (object sender, EventArgs e) =>
            {
                try
                {
                    var status = Register(txtFirstName.Text, txtLastName.Text, txtEmail.Text, txtPassword.Text);
                    if (status == RegisterStatus.SUCCESS)
                    {
                        User user = new User
                        {
                            Id = 1,
                            FirstName = txtFirstName.Text.Trim(),
                            LastName = txtLastName.Text.Trim(),
                            Email = txtEmail.Text.Trim(),
                            Password = txtPassword.Text.Trim()

                        };
                        Intent intent = new Intent(this, typeof(MenuActivity));
                        intent.PutExtra("User", JsonConvert.SerializeObject(user));
                        user.SaveCacheUserInfo(user);
                        StartActivity(intent);
                    }
                    else if (status == RegisterStatus.INVALID_CREDENTIAL)
                    {
                        Utilities.ToastMessage(this, Utilities.ToastMessageType.ERROR, "Either email or password not valid, please enter a valid one.");
                    }
                    else
                    {
                        Utilities.ToastMessage(this, Utilities.ToastMessageType.ERROR, "Connection failed, Please check your network connection");
                    }
                }
                catch (Exception ex)
                {

                    Utilities.ToastMessage(this, Utilities.ToastMessageType.EXCEPTION, ex.ToString());
                }
            };
        }
Пример #3
0
        public User GetCacheUserInfo()
        {
            ISharedPreferences sharedPreferences = Application.Context.GetSharedPreferences("UserInfo", FileCreationMode.Private);
            string authKey = sharedPreferences.GetString("AuthKey", string.Empty);
            string id = sharedPreferences.GetString("Id", "0");
            string firstName = sharedPreferences.GetString("FirstName", string.Empty);
            string lastName = sharedPreferences.GetString("LastName", string.Empty);
            string email = sharedPreferences.GetString("Email", string.Empty);
            string password = sharedPreferences.GetString("Password", string.Empty);
            User user = new User
            {
                Id = int.Parse(id),
                FirstName = firstName,
                LastName = lastName,
                Email = email,
                Password = password

            };

            return user;
        }
Пример #4
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Main);
            var result = ServerCommunication.GetAuthKey();
            if (result.Contains("EXCEPTION"))
                Utilities.ToastMessage(this, Utilities.ToastMessageType.EXCEPTION, result);
            else
                Utilities.ToastMessage(this, Utilities.ToastMessageType.INFO, result);
            Button btnFacebookm = FindViewById<Button>(Resource.Id.btnFacebookTemp);
            btnFacebookm.Click += (object sender, EventArgs e) =>
            {
                StartActivity(typeof(LoginActivity));
            };
            Button btnEmail = FindViewById<Button>(Resource.Id.btnEmail);
            btnEmail.Click += (sender, e) =>
            {
                StartActivity(typeof(RegisterActivity));
            };
            Button btnAlready = FindViewById<Button>(Resource.Id.btnAlready);
            btnAlready.Click += (sender, e) =>
            {
                User user = new User();
                var tempUser = user.GetCacheUserInfo();

                if (tempUser.Email == String.Empty || tempUser.Password == String.Empty)
                {
                    Intent intent = new Intent(this, typeof(LoginActivity));
                    this.StartActivity(intent);
                }
                else
                {
                    Intent intent = new Intent(this, typeof(MenuActivity));
                    intent.PutExtra("User", JsonConvert.SerializeObject(user));
                    StartActivity(intent);
                }

            };
        }
Пример #5
0
        private LoginStatus Login(string authKey, string email, string password)
        {
            LoginStatus status;
            if (validation.ValidateEmail(email) && validation.ValidatePassword(password))
            {

                string jsonInput = "{\"emailid\":\"" + email + "\",\"password\":\"" + password + "\",\"authtoken\":\"" + AppConfig.Auth_Token + "\"}";
                var loginJson = ServerCommunication.ServerCallWebRequest(AppConfig.URL_LOGIN, jsonInput);
                LoginResponse loginResponse = JsonConvert.DeserializeObject<LoginResponse>(loginJson);
                if (loginResponse.Response.status == "success")
                {
                    if (cbxRememberMe.Checked)
                    {
                        User user = new User { AuthKey = authKey, Email = email, Password = password };
                        user.SaveCacheUserInfo(user);
                    }
                    status = LoginStatus.SUCCESS;
                }
                else
                {
                    status = LoginStatus.FAILED;
                }
            }
            else
            {
                status = LoginStatus.INVALID_CREDENTIAL;
            }
            return status;
        }