Example #1
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());
                }
            };
        }
Example #2
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;
        }