コード例 #1
0
        public override void Post(HttpRequest Request, HttpResponse Response, params string[] PathParams)
        {
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Cache.SetMaxAge(TimeSpan.Zero);

            JObject inputData = null;
            try
            {
                using (StreamReader reader = new StreamReader(Request.InputStream))
                {
                    using (JsonTextReader jsonReader = new JsonTextReader(reader))
                    {
                        inputData = JObject.Load(jsonReader);
                    }
                }
            }
            catch
            {
                RespondBadRequest(Response);
            }

            string email = inputData.Value<string>(@"email") ?? "";
            string password = inputData.Value<string>(@"password") ?? "";

            Response.ContentType = @"application/json";

            Int64 SupplierId;
            AppMembership.AppUserAuthenticateResults res = AppMembership.AuthenticateAppSupplier(email, password, out SupplierId);
            switch (res)
            {
                case AppMembership.AppUserAuthenticateResults.Success:
                    {
                        List<object> SupplierStatus = new List<object>();
                        AppSupplierAuthToken at = AuthTokens.GenerateAuthTokenForAppSupplierId(SupplierId, 0);

                        try
                        {
                            AppMembership.AppSupplierLoggedInAction(SupplierId, out SupplierStatus);
                        }
                        catch { }

                        using (StreamWriter streamWriter = new StreamWriter(Response.OutputStream))
                        {
                            using (JsonTextWriter jsonWriter = new JsonTextWriter(streamWriter))
                            {
                                jsonWriter.WriteStartObject();

                                jsonWriter.WritePropertyName(@"access_token");
                                jsonWriter.WriteValue(AuthTokens.AccessToken(at));

                                jsonWriter.WritePropertyName(@"user_id");
                                jsonWriter.WriteValue(SupplierId);

                                jsonWriter.WritePropertyName(@"status");
                                jsonWriter.WriteValue(SupplierStatus.Count > 0 ? SupplierStatus[0] : false);

                                jsonWriter.WritePropertyName(@"allow_change_status_join_bids");
                                jsonWriter.WriteValue(SupplierStatus.Count > 0 ? SupplierStatus[1] : false);

                                jsonWriter.WritePropertyName(@"is_auto_join_bid");
                                jsonWriter.WriteValue(SupplierStatus.Count > 0 ? SupplierStatus[2] : false);
                                
                                jsonWriter.WritePropertyName(@"is_service_supplier");
                                jsonWriter.WriteValue(SupplierStatus.Count > 0 ? SupplierStatus[4] : false);

                                jsonWriter.WritePropertyName(@"max_winning_num");
                                jsonWriter.WriteValue(SupplierStatus.Count > 0 ? SupplierStatus[3] : 0);

                                jsonWriter.WriteEndObject();
                            }
                        }
                    }
                    break;
                default:
                case AppMembership.AppUserAuthenticateResults.LoginError:
                    {
                        RespondBadRequest(Response);
                    }
                    break;
                case AppMembership.AppUserAuthenticateResults.NotVerified:
                    {
                        RespondError(Response, HttpStatusCode.Forbidden, @"not-verified");
                    }
                    break;
                case AppMembership.AppUserAuthenticateResults.NoMatch:
                    {
                        RespondError(Response, HttpStatusCode.Forbidden, @"no-match");
                    }
                    break;
                case AppMembership.AppUserAuthenticateResults.Locked:
                    {
                        RespondError(Response, HttpStatusCode.Forbidden, @"locked");
                    }
                    break;
            }
        }
コード例 #2
0
        public override void Post(HttpRequest Request, HttpResponse Response, params string[] PathParams)
        {
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Cache.SetMaxAge(TimeSpan.Zero);

            JObject inputData = null;

            try
            {
                using (StreamReader reader = new StreamReader(Request.InputStream))
                {
                    using (JsonTextReader jsonReader = new JsonTextReader(reader))
                    {
                        inputData = JObject.Load(jsonReader);
                    }
                }
            }
            catch
            {
                RespondBadRequest(Response);
            }

            string email      = inputData.Value <string>(@"email") ?? "";
            string password   = inputData.Value <string>(@"password") ?? "";
            string lang_code  = inputData.Value <string>(@"lang_code") ?? "";
            bool   isTestUser = inputData.Value <bool>(@"is_test_user");

            Int64 tempAppUserId = inputData.Value <Int64>(@"temp_app_user_id");

            Response.ContentType = @"application/json";
            if (isTestUser)
            {
                User userBack;
                Membership.TestUser(email, password.Trim(), out userBack);
                RespondBadRequest(Response, @"is_succeeded", (userBack != null).ToString());
            }

            AppUser user;

            AppMembership.AppUserCreateResults res = AppMembership.CreateAppUser(email, password, lang_code, out user);

            switch (res)
            {
            case AppMembership.AppUserCreateResults.Success:
            {
                using (StreamWriter streamWriter = new StreamWriter(Response.OutputStream))
                {
                    using (JsonTextWriter jsonWriter = new JsonTextWriter(streamWriter))
                    {
                        if (!user.IsVerified && Settings.GetSettingBool(Settings.Keys.APPUSER_VERIFY_EMAIL, false))
                        {
                            jsonWriter.WriteStartObject();

                            jsonWriter.WritePropertyName(@"needs_verification");
                            jsonWriter.WriteValue(true);

                            jsonWriter.WriteEndObject();
                        }
                        else
                        {
                            AppUserAuthToken at = AuthTokens.GenerateAuthTokenForAppUserId(user.AppUserId, 0);

                            jsonWriter.WriteStartObject();

                            //jsonWriter.WritePropertyName(@"auth_token_secret");
                            //jsonWriter.WriteValue(at.Secret.ToString(@"N"));

                            //jsonWriter.WritePropertyName(@"auth_token_key");
                            //jsonWriter.WriteValue(at.Key);
                            if (tempAppUserId != 0)
                            {
                                BidController.UpdateTempAppUserBidsToUserBid(tempAppUserId, user.AppUserId);
                            }
                            jsonWriter.WritePropertyName(@"access_token");
                            jsonWriter.WriteValue(AuthTokens.AccessToken(at));

                            jsonWriter.WritePropertyName(@"user_id");
                            jsonWriter.WriteValue(user.AppUserId);

                            jsonWriter.WriteEndObject();
                        }
                    }
                }
            }
            break;

            case AppMembership.AppUserCreateResults.AlreadyExists:
            {
                RespondBadRequest(Response, @"user-already-exists", @"the supplied email address is in use");
            }
            break;

            case AppMembership.AppUserCreateResults.InvalidEmailAddress:
            {
                RespondBadRequest(Response, @"invalid-email", @"the supplied email address is invalid");
            }
            break;

            default:
            case AppMembership.AppUserCreateResults.UnknownError:
            {
                RespondInternalServerError(Response);
            }
            break;
            }
        }
コード例 #3
0
        public override void Post(HttpRequest Request, HttpResponse Response, params string[] PathParams)
        {
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Cache.SetMaxAge(TimeSpan.Zero);

            JObject inputData = null;

            try
            {
                using (StreamReader reader = new StreamReader(Request.InputStream))
                {
                    using (JsonTextReader jsonReader = new JsonTextReader(reader))
                    {
                        inputData = JObject.Load(jsonReader);
                    }
                }
            }
            catch
            {
                RespondBadRequest(Response);
            }

            string accessToken = inputData.Value <string>(@"access_token") ?? "";

            Response.ContentType = @"application/json";

            AppUser user;

            AppMembership.AppUserFacebookConnectResults res = AppMembership.ConnectAppUserToFacebook(accessToken, out user);
            switch (res)
            {
            case AppMembership.AppUserFacebookConnectResults.Success:
            {
                AppUserAuthToken at = AuthTokens.GenerateAuthTokenForAppUserId(user.AppUserId, 0);

                using (StreamWriter streamWriter = new StreamWriter(Response.OutputStream))
                {
                    using (JsonTextWriter jsonWriter = new JsonTextWriter(streamWriter))
                    {
                        jsonWriter.WriteStartObject();

                        jsonWriter.WritePropertyName(@"access_token");
                        jsonWriter.WriteValue(AuthTokens.AccessToken(at));

                        jsonWriter.WritePropertyName(@"user_id");
                        jsonWriter.WriteValue(user.AppUserId);

                        Int64?cityId = user.CityId;
                        jsonWriter.WritePropertyName(@"is_city_exists");
                        jsonWriter.WriteValue(cityId != null && cityId != 0);

                        jsonWriter.WriteEndObject();
                    }
                }
            }
            break;

            default:
            case AppMembership.AppUserFacebookConnectResults.LoginError:
            {
                RespondForbidden(Response);
            }
            break;
            }
        }
コード例 #4
0
        public override void Post(HttpRequest Request, HttpResponse Response, params string[] PathParams)
        {
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Cache.SetMaxAge(TimeSpan.Zero);

            JObject inputData = null;

            try
            {
                using (StreamReader reader = new StreamReader(Request.InputStream))
                {
                    using (JsonTextReader jsonReader = new JsonTextReader(reader))
                    {
                        inputData = JObject.Load(jsonReader);
                    }
                }
            }
            catch
            {
                RespondBadRequest(Response);
            }

            string email    = inputData.Value <string>(@"email") ?? "";
            string password = inputData.Value <string>(@"password") ?? "";

            Response.ContentType = @"application/json";

            Int64 AppUserId;

            AppMembership.AppUserAuthenticateResults res = AppMembership.AuthenticateAppUser(email, password, out AppUserId);
            switch (res)
            {
            case AppMembership.AppUserAuthenticateResults.Success:
            {
                AppUserAuthToken at = AuthTokens.GenerateAuthTokenForAppUserId(AppUserId, 0);

                try
                {
                    AppMembership.AppUserLoggedInAction(AppUserId);
                }
                catch { }

                using (StreamWriter streamWriter = new StreamWriter(Response.OutputStream))
                {
                    using (JsonTextWriter jsonWriter = new JsonTextWriter(streamWriter))
                    {
                        jsonWriter.WriteStartObject();

                        jsonWriter.WritePropertyName(@"access_token");
                        jsonWriter.WriteValue(AuthTokens.AccessToken(at));

                        jsonWriter.WritePropertyName(@"user_id");
                        jsonWriter.WriteValue(AppUserId);

                        Int64?cityId = AppUser.FetchByID(AppUserId).CityId;
                        jsonWriter.WritePropertyName(@"is_city_exists");
                        jsonWriter.WriteValue(cityId != null && cityId != 0);

                        jsonWriter.WriteEndObject();
                    }
                }
            }
            break;

            default:
            case AppMembership.AppUserAuthenticateResults.LoginError:
            {
                RespondBadRequest(Response);
            }
            break;

            case AppMembership.AppUserAuthenticateResults.NotVerified:
            {
                RespondError(Response, HttpStatusCode.Forbidden, @"not-verified");
            }
            break;

            case AppMembership.AppUserAuthenticateResults.NoMatch:
            {
                RespondError(Response, HttpStatusCode.Forbidden, @"no-match");
            }
            break;

            case AppMembership.AppUserAuthenticateResults.Locked:
            {
                RespondError(Response, HttpStatusCode.Forbidden, @"locked");
            }
            break;
            }
        }