コード例 #1
0
        public ActionResult GetUsername(string UserName)
        {
            const int max     = 30;
            const int min     = 3;
            var       message = "Username is valid for registration.";

            try {
                if (UserName == null || UserName.Length < 3)
                {
                    goto ReturnInvalid;
                }
                if (!AppVar.Setting.IsInTestingEnvironment)
                {
                    if (SessionNames.IsValidationExceed("username"))
                    {
                        return(Json(Validator.GetErrorValidationExceedMessage(), JsonRequestBehavior.AllowGet));
                    }
                }
                const string userPattern = "^([A-Za-z]|[A-Za-z0-9_.]+)$";
                if (Regex.IsMatch(UserName, userPattern, RegexOptions.Compiled) && UserName.Length >= min &&
                    UserName.Length <= max)
                {
                    if (!UserManager.IsUserNameExist(UserName))
                    {
                        return(Json(Validator.GetSuccessMessage(message), JsonRequestBehavior.AllowGet));
                    }
                }
            } catch (Exception ex) {
                AppVar.Mailer.HandleError(ex, "Validate Username");
            }
ReturnInvalid:
            message = "Username already exist or not valid.";
            return(Json(Validator.GetErrorMessage(message), JsonRequestBehavior.AllowGet));
        }
        public ActionResult Email(string id, string requestVerificationToken)
        {
            if (SessionNames.IsValidationExceed("Email"))
            {
                return(Json(false, JsonRequestBehavior.AllowGet));
            }
            try {
                if (id == null || id.Length < 5)
                {
                    return(Json(false, JsonRequestBehavior.AllowGet));
                }

                var email = id;

                var emailPattern = @"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$";
                if (Regex.IsMatch(email, emailPattern))
                {
                    if (!UserManager.IsEmailExist(email))
                    {
                        return(Json(true, JsonRequestBehavior.AllowGet));
                    }
                }
                return(Json(false, JsonRequestBehavior.AllowGet));
            } catch (Exception ex) {
                AppVar.Mailer.HandleError(ex, "Validate Email");

                return(Json(false));
            }
        }
コード例 #3
0
        public ActionResult GetEmail(string Email)
        {
            const string errorMessage = "Email already exist or not valid.";

            if (!AppVar.Setting.IsInTestingEnvironment)
            {
                if (SessionNames.IsValidationExceed("Email"))
                {
                    return(Json(Validator.GetErrorValidationExceedMessage(), JsonRequestBehavior.AllowGet));
                }
            }
            try {
                if (Email == null || Email.Length < 5)
                {
                    goto ReturnInvalid;
                }
                var email = Email;

                var emailPattern = @"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$";
                if (Regex.IsMatch(email, emailPattern))
                {
                    if (!UserManager.IsEmailExist(email))
                    {
                        return(Json(Validator.GetSuccessMessage("Valid email."), JsonRequestBehavior.AllowGet));
                    }
                }
            } catch (Exception ex) {
                AppVar.Mailer.HandleError(ex, "Validate Email");
            }
ReturnInvalid:
            return(Json(Validator.GetErrorMessage(errorMessage), JsonRequestBehavior.AllowGet));
        }
コード例 #4
0
        public ActionResult GetTags(string id)
        {
            if (SessionNames.IsValidationExceed("GetTags", 500) || string.IsNullOrWhiteSpace(id))
            {
                return(Json(null, JsonRequestBehavior.AllowGet));
            }

            using (var db = new ReviewAppsEntities()) {
                var tags = db.Tags.Where(n => n.TagDisplay.StartsWith(id))
                           .Select(n => n.TagDisplay).Take(10).ToArray();

                var list = new List <string>(25);
                foreach (var tag in tags)
                {
                    list.Add(tag);
                }
                if (id.Length > 3)
                {
                    var tags2 =
                        db.Tags.Where(n => n.TagDisplay.Contains(id) && tags.All(found => found != n.TagDisplay))
                        .Select(n => n.TagDisplay).Take(10).ToArray();
                    foreach (var tag in tags2)
                    {
                        list.Add(tag);
                    }
                }
                return(Json(list, JsonRequestBehavior.AllowGet));
            }
            ;
        }
        public ActionResult Username(string id, string requestVerificationToken)
        {
            var returnParam = true;
            var max         = 30;
            var min         = 3;

            try {
                if (id == null || id.Length < 3)
                {
                    return(Json(!returnParam, JsonRequestBehavior.AllowGet));
                }
                if (SessionNames.IsValidationExceed("username"))
                {
                    throw new Exception("Exceed the limit of try");
                }
                var userPattern = "^([A-Za-z]|[A-Za-z0-9_.]+)$";
                if (Regex.IsMatch(id, userPattern, RegexOptions.Compiled) && (id.Length >= min && id.Length <= max))
                {
                    if (UserManager.IsUserNameExist(id))
                    {
                        return(Json(!returnParam, JsonRequestBehavior.AllowGet));
                    }
                    return(Json(returnParam, JsonRequestBehavior.AllowGet)); // only true
                }
            } catch (Exception ex) {
                AppVar.Mailer.HandleError(ex, "Validate Username");
            }
            //found e false
            return(Json(!returnParam, JsonRequestBehavior.AllowGet));
        }
コード例 #6
0
        public ActionResult ResetPassword(long userId, string email, string code, Guid guid)
        {
            var name          = "reset-pass-" + guid.GetHashCode().ToString();
            var blocked       = SessionNames.IsValidationExceed("Account.ResetPassword");
            var isAlreadySent = !AppVar.IsInTestEnvironment && Session[name] != null;

            if (!isAlreadySent && !blocked)
            {
                if (code == null || !Manager.VerifyUserToken(userId, TokenPurpose.ResetPassword, code))
                {
                    return(View("Error"));
                }
                var user = User.GetUser(userId);
                if (user != null)
                {
                    if (string.Compare(email, user.Email, StringComparison.OrdinalIgnoreCase) == 0 &&
                        user.GeneratedGuid.HasValue &&
                        user.GeneratedGuid.Value == guid)
                    {
                        User.SaveUserInSession(user, SessionNames.EmailResetExecute);
                        var model = new ResetPasswordViewModel {
                            Code  = code,
                            Email = email
                        };
                        Session[name] = "set";
                        return(View(model));
                    }
                }
            }
            ViewBag.message = "You have already sent a request few minutes ago!";
            return(View("ResetPasswordConfirmation"));
        }
コード例 #7
0
        public ActionResult Index(string SearchQuery)
        {
            var max = 60;

            var search     = new SearchViewModel();
            var algorithms = new Logics();

            //ViewBag.isPostBack = true;
            if (!string.IsNullOrWhiteSpace(SearchQuery))
            {
                if (!AppVar.Setting.IsInTestingEnvironment)
                {
                    if (SessionNames.IsValidationExceed("SearchingFormCount", max))
                    {
                        var errorRoute = new ErrorsController();
                        return(errorRoute.Error(429, null,
                                                "You have exceed your search cases. Perhaps you should try tomorrow."));
                    }
                }
                search.SearchQuery = SearchQuery;
                var urlGet      = algorithms.GenerateHyphenUrlString(SearchQuery);
                var displayList = urlGet.Split('-');
                var displayStr  = string.Join(" ", displayList);
                var results     = algorithms.GetSearchResults(SearchQuery, null, null, null,
                                                              Variables.SearchResultsMaxResultReturn);
                search.DisplayStringToUser = displayStr;
                search.FoundApps           = results;
                return(View(search));
            }
            search.DisplayStringToUser = "";
            search.FoundApps           = null;
            return(View(search));
        }
コード例 #8
0
        private void ResetSessionForUploadSequence(Guid uploadGuid)
        {
            var id      = uploadGuid.ToString();
            var keysArr = new[] { id, id + "-count", id + "-staticCount" };

            SessionNames.RemoveKeys(keysArr);
        }
コード例 #9
0
        public ActionResult Review(long id)
        {
            if (SessionNames.IsValidationExceed("Review-Report"))
            {
                return(View("Later"));
            }
            if (RoleManager.IsInRole(RoleNames.Rookie) == false)
            {
                // at least has a role.
                // since lowest priority role, it will be added while registering a user.
                return(AppVar.GetAuthenticationError("Unauthorized", ""));
            }

            Review review;
            App    app;
            var    isReportedAlready = IsReviewAlreadyReported(id, out review, out app);

            if (isReportedAlready == false && review != null)
            {
                ViewBag.app    = app;
                ViewBag.review = review;
                ViewBag.id     = id;
                return(View());
            }
            if (isReportedAlready && review != null)
            {
                return(View("AlreadyReported"));
            }
            return(View("_404"));
        }
コード例 #10
0
        /// <summary>
        /// </summary>
        /// <param name="id">AppId</param>
        /// <returns></returns>
        public ActionResult App(long id)
        {
            if (SessionNames.IsValidationExceed("App-Report"))
            {
                return(View("Later"));
            }
            if (RoleManager.IsInRole(RoleNames.Rookie) == false)
            {
                return(AppVar.GetAuthenticationError("Unauthorized", ""));
            }
            // if the app is already reported.
            App app;
            var isAlreadyReported = IsAppAlreadyReported(id, out app);

            if (app != null)
            {
                if (isAlreadyReported)
                {
                    ViewBag.isAppReport = true; // if the app is already reported
                    return(View("AlreadyReported"));
                }
                ViewBag.id  = id;
                ViewBag.app = app;
                return(View());
            }
            return(View("_404"));
        }
コード例 #11
0
        public ActionResult GetValidUrlEditing(App app)
        {
            var max     = 60;
            var min     = 3;
            var id      = app.AppName;
            var message = "Username is valid for registration.";

            try {
                if (id == null || id.Length < 5)
                {
                    goto ReturnInvalid;
                }
                if (!AppVar.Setting.IsInTestingEnvironment)
                {
                    if (SessionNames.IsValidationExceed("GetValidUrl"))
                    {
                        return(Json(Validator.GetErrorValidationExceedMessage(), JsonRequestBehavior.AllowGet));
                    }
                }

                if (id.Length >= min && id.Length <= max)
                {
                    var url = GetFriendlyURLFromString(id);
                    if (app.Url != null && app.Url.Equals(url))
                    {
                        goto ReturnValid;
                    }
                    using (var db = new ReviewAppsEntities()) {
                        var exist =
                            db.Apps.Any(
                                n =>
                                n.AppID != app.AppID && n.PlatformID == app.PlatformID &&
                                n.CategoryID == app.CategoryID && n.Url == url &&
                                n.PlatformVersion == app.PlatformVersion);
                        if (!exist)
                        {
                            goto ReturnValid;
                        }
                        goto ReturnInvalid;
                    }
                }
            } catch (Exception ex) {
                AppVar.Mailer.HandleError(ex, "Validate GetValidUrl App-Editing");
            }
            //found e false
ReturnValid:
            return(Json(Validator.GetSuccessMessage("App name is already exist or not valid."),
                        JsonRequestBehavior.AllowGet)); // return true;

ReturnInvalid:
            return(Json(Validator.GetErrorMessage("App name is not valid."), JsonRequestBehavior.AllowGet));
        }
コード例 #12
0
        public static object Session(SessionNames session, object _default)
        {
            var result = Session(session);

            if (result == null)
            {
                return(_default);
            }
            else
            {
                return(result);
            }
        }
コード例 #13
0
 public ActionResult GetFeedbackCategoryID()
 {
     if (SessionNames.IsValidationExceed("GetFeedbackCategoryID", 100))
     {
         return(Json(null, JsonRequestBehavior.AllowGet));
     }
     using (var db = new ApplicationDbContext()) {
         var categories = db.FeedbackCategories
                          .Select(n => new { display = n.Category, id = n.FeedbackCategoryID })
                          .ToList();
         return(Json(categories, JsonRequestBehavior.AllowGet));
     }
 }
        public ActionResult GetTimeZone(int id)
        {
            if (SessionNames.IsValidationExceed("GetTimeZone", 100))
            {
                return(Json(null, JsonRequestBehavior.AllowGet));
            }
            var getZones = CachedQueriedData.GetTimezones(id);

            if (getZones != null)
            {
                var represent = getZones.Select(n => new { text = n.Display, id = n.UserTimeZoneID });
                return(Json(represent.ToList(), JsonRequestBehavior.AllowGet));
            }
            return(Json(null, JsonRequestBehavior.AllowGet));
        }
        //[OutputCache(CacheProfile = "Day", VaryByParam = "id")]
        public ActionResult GetLanguage(int id)
        {
            if (SessionNames.IsValidationExceed("GetLanguage", 100))
            {
                return(Json(null, JsonRequestBehavior.AllowGet));
            }
            var languges = CachedQueriedData.GetLanguages(id);

            if (languges != null)
            {
                var represent =
                    languges.Select(n => new { text = n.Language + " - " + n.NativeName, id = n.CountryLanguageID });
                return(Json(represent.ToList(), JsonRequestBehavior.AllowGet));
            }
            return(Json(null, JsonRequestBehavior.AllowGet));
        }
コード例 #16
0
ファイル: Project.cs プロジェクト: z-saffarpour/duscusys
        public bool RemoveSessionName(string sessionName)
        {
            if (!SessionNames.Contains(sessionName))
            {
                return(false);
            }

            //remove sessions with the given type
            foreach (var s in Sessions.Where(s => s.Name == sessionName).ToArray())
            {
                Sessions.Remove(s);
            }

            SessionNames.Remove(sessionName);

            return(true);
        }
コード例 #17
0
ファイル: Project.cs プロジェクト: z-saffarpour/duscusys
        public bool AddSessionName(string name)
        {
            if (SessionNames.Contains(name))
            {
                return(false);
            }

            SessionNames.Add(name);

            //generate sessions with the new name
            foreach (var sessionType in SessionTypes)
            {
                Sessions.Add(new Session(name, sessionType));
            }

            return(true);
        }
コード例 #18
0
        public async Task <ActionResult> Review(Feedback feedback, long appOrReviewId, bool hasAppId)
        {
            if (SessionNames.IsValidationExceed("Review-Report"))
            {
                return(View("Later"));
            }
            if (RoleManager.IsInRole(RoleNames.Rookie) == false)
            {
                // at least has a role.
                // since lowest priority role, it will be added while registering a user.
                return(AppVar.GetAuthenticationError("Unauthorized", ""));
            }
            Review review;
            App    app;
            var    isReportedAlready = IsReviewAlreadyReported(appOrReviewId, out review, out app);

            if (isReportedAlready == false && review != null)
            {
                // review is not reported before by this user.
                if (!ModelState.IsValid)
                {
                    // non valid message.
                    ViewBag.errorMessage = MessageConstants.JunkMessageResult;
                    ViewBag.id           = appOrReviewId;
                    ViewBag.review       = review;
                    ViewBag.app          = app;
                    return(View(feedback));
                }
                // now post the report.
                db2.Feedbacks.Add(feedback);
                // add the relationship and category.
                AttachNewRelationship(feedback, appOrReviewId, false);
                if (db2.SaveChanges() > -1)
                {
                    // successfully saved.
                    // async send an email to the admin.
                    RemoveSessionCache(appOrReviewId, false);
                    AppVar.Mailer.NotifyAdmin("A user has reported a review.",
                                              "Hi , <br>Please login and check at the admin panel , a review has been reported.");
                    return(View("Done"));
                }
                return(View());
            }
            return(View("AlreadyReported"));
        }
コード例 #19
0
        public ActionResult GetAppUrl(App app)
        {
            if (SessionNames.IsValidationExceed("GetAppUrl", 500) || app == null)
            {
                return(Json(null, JsonRequestBehavior.AllowGet));
            }
            using (var db = new ReviewAppsEntities()) {
                var algorithms = new Logics();

                app.Url = algorithms.GenerateHyphenUrlStringValid(app, db);

                var sender = new {
                    url = app.GetAbsoluteUrl()
                };
                return(Json(sender, JsonRequestBehavior.AllowGet));
            }
            ;
        }
コード例 #20
0
 public static object Session(SessionNames session)
 {
     return(HttpContext.Current.Session[session.ToString()]);
 }
コード例 #21
0
 /// <summary>
 ///     Remove global error list from session.
 /// </summary>
 /// <returns></returns>
 public static void RemoveGlobalError()
 {
     SessionNames.RemoveKey(SessionNames.Error);
 }
コード例 #22
0
 public static void SetSession(SessionNames session, object value)
 {
     HttpContext.Current.Session[session.ToString()] = value;
 }
コード例 #23
0
ファイル: UserManager.cs プロジェクト: aukgit/Review-Apps.net
 /// <summary>
 /// Clear user from session SessionNames.UserID, SessionNames.LastUser, SessionNames.UserCache
 /// </summary>
 public static void ClearUserSessions()
 {
     SessionNames.RemoveKeys(new[] { SessionNames.UserID, SessionNames.LastUser, SessionNames.UserCache });
     GC.Collect();
 }
コード例 #24
0
ファイル: UserCache.cs プロジェクト: aukgit/Review-Apps.net
 /// <summary>
 ///     Clear usercache object session.
 /// </summary>
 public static void ClearSession()
 {
     SessionNames.RemoveKey(SessionNames.UserCache);
 }