Exemple #1
0
        public async Task <ActionResult> proc()
        {
            var json = new StreamReader(Request.Body).ReadToEnd();
            var data = JsonConvert.DeserializeObject <ApplicationUser>(json);

            if (data.Id != null && data.Id != "")
            {
                // Update Profile
                var record = await UserBLL.Update_User_Profile(_context, data, data.isadmin);

                /* attribute processing */
                foreach (var attr in data.attr_values)
                {
                    attr.userid    = data.Id;
                    attr.attr_type = (byte)Attr_Type.UserProfile;
                    if (attr.id > 0)
                    {
                        /* update record */
                        await AttrValueBLL.Update(_context, attr);
                    }
                    else
                    {
                        /* add attribute */
                        if (attr.value != "")
                        {
                            await AttrValueBLL.Add(_context, attr);
                        }
                    }
                }

                record.img_url = UserUrlConfig.ProfilePhoto(record.UserName, record.picturename, 0);
                return(Ok(new { status = "success", record = record, message = SiteConfig.generalLocalizer["_record_updated"].Value }));
            }
            else
            {
                // Create New Account
                var user = new ApplicationUser
                {
                    UserName   = data.UserName,
                    Email      = data.Email,
                    created_at = DateTime.Now,
                    isenabled  = 1, // internal use only (to suspend user account and all posted data at once)
                    firstname  = data.firstname,
                    lastname   = data.lastname
                };

                var result = await SiteConfig.userManager.CreateAsync(user, data.password);

                if (result.Succeeded)
                {
                    // role process
                    if (data.role_name != null && data.role_name != "")
                    {
                        var roleExist = await SiteConfig.roleManager.RoleExistsAsync(data.role_name);

                        if (!roleExist)
                        {
                            ApplicationRole role = new ApplicationRole();
                            role.Name        = data.role_name;
                            role.CreatedDate = DateTime.Now;
                            await SiteConfig.roleManager.CreateAsync(role);
                        }

                        await SiteConfig.userManager.AddToRoleAsync(user, data.role_name);
                    }

                    // Init User Profile
                    await UserProfileBLL.InitializeUserProfile(_context, user);

                    Directory_Process.CreateRequiredDirectories(SiteConfig.Environment.ContentRootPath + UtilityBLL.ParseUsername(SystemDirectoryPaths.UserDirectory, user.Id.ToString()));

                    // enable account directly
                    UserBLL.Update_Field_Id(_context, user.Id, "EmailConfirmed", true);

                    // setup url / picture url for app use only
                    data.Id             = user.Id;
                    data.picturename    = "none";
                    data.LockoutEnabled = false;
                    data.EmailConfirmed = true;
                    data.img_url        = UserUrlConfig.ProfilePhoto(data.UserName, data.picturename, 0); // default set
                    data.url            = UserUrlConfig.ProfileUrl(data, Configs.RegistrationSettings.uniqueFieldOption);

                    return(Ok(new { status = "success", record = data, message = SiteConfig.generalLocalizer["_account_created"].Value }));
                }
                else
                {
                    return(Ok(new { status = "error", record = data, message = SiteConfig.generalLocalizer["_account_failed"].Value }));
                }
            }
        }
Exemple #2
0
        public async Task <IActionResult> profile(string username)
        {
            var model = new UserModelView();

            model.ActiveIndex = 10; // profile section

            if (!InitProfile(model, username))
            {
                return(Redirect(Config.GetUrl() + "signin?ReturnUrl=" + Config.GetUrl(username)));
            }

            if (!InitProfile(model, username))
            {
                return(Redirect(Config.GetUrl() + "signin?ReturnUrl=" + Config.GetUrl(username)));
            }

            // fetch profile user information
            var query = new MemberEntity()
            {
                ispublic = true,
                loadall  = true
            };

            if (Jugnoon.Settings.Configs.RegistrationSettings.uniqueFieldOption == 0)
            {
                query.username = model.UserName;
            }
            else
            {
                query.userid = model.UserName;
            }


            var userInfo = await UserProfileBLL.LoadItems(_context, query);

            if (userInfo.Count > 0)
            {
                model.user = userInfo[0];
                // load dynamic attributes
                model.attr_values = await AttrValueBLL.LoadItems(_context, new AttrValueEntity()
                {
                    userid    = model.user.Id,
                    attr_type = Attr_Type.UserProfile,
                    order     = "priority desc",
                    nofilter  = false
                });


                model.UserInfo = prepare_user_info(model);

                model.FullName = UserUrlConfig.PrepareUserName(model.user, Jugnoon.Settings.Configs.RegistrationSettings.uniqueFieldOption);

                model.Nav = new NavModelView()
                {
                    username    = model.UserName,
                    ActiveIndex = 100,
                };
            }
            else
            {
                model.UserExist = false;
            }


            ViewBag.title = model.FullName + "'s " + SiteConfig.generalLocalizer["_profile_detail"].Value;

            return(View(model));
        }
Exemple #3
0
        public async Task <ActionResult> getinfo()
        {
            var json = new StreamReader(Request.Body).ReadToEnd();
            var data = JsonConvert.DeserializeObject <MemberEntity>(json);

            if (data.id == "")
            {
                var _post = new ApplicationUser();
                _post.options = await AttrTemplatesSectionsBLL.LoadItems(_context, new AttrTemplateSectionEntity()
                {
                    templateid = 0, // if you want to manage multiple templates for dynamic attributes use it here
                    attr_type  = Attr_Type.UserProfile,
                    order      = "priority desc",
                    iscache    = true
                });

                foreach (var option in _post.options)
                {
                    option.attributes = await AttrAttributeBLL.LoadItems(_context, new AttrAttributeEntity()
                    {
                        sectionid = option.id,
                        order     = "priority desc",
                        iscache   = true,
                        attr_type = (byte)Attr_Type.UserProfile
                    });
                }
                return(Ok(new { status = "success", post = _post }));
            }
            else
            {
                var _posts = await UserProfileBLL.LoadItems(_context, data);

                if (_posts.Count == 0)
                {
                    return(Ok(new { status = "error", message = SiteConfig.generalLocalizer["_no_records"].Value }));
                }

                // Raw Attributes
                _posts[0].options = await AttrTemplatesSectionsBLL.LoadItems(_context, new AttrTemplateSectionEntity()
                {
                    templateid = 0, // if you want to manage multiple templates for dynamic attributes use it here
                    order      = "priority desc",
                    attr_type  = Attr_Type.UserProfile,
                    iscache    = true
                });

                foreach (var option in _posts[0].options)
                {
                    option.attributes = await AttrAttributeBLL.LoadItems(_context, new AttrAttributeEntity()
                    {
                        sectionid = option.id,
                        order     = "priority desc",
                        iscache   = true,
                        attr_type = (byte)Attr_Type.UserProfile
                    });
                }

                _posts[0].attr_values = await AttrValueBLL.LoadItems(_context, new AttrValueEntity()
                {
                    userid    = _posts[0].Id,
                    attr_type = Attr_Type.UserProfile,
                    nofilter  = false
                });

                _posts[0].img_url = UserUrlConfig.ProfilePhoto(_posts[0].UserName, _posts[0].picturename, 0); // default set
                _posts[0].url     = UserUrlConfig.ProfileUrl(_posts[0], Configs.RegistrationSettings.uniqueFieldOption);
                _posts[0].customize_register_date = UtilityBLL.CustomizeDate((DateTime)_posts[0].created_at, DateTime.Now);
                if (_posts[0].last_login != null)
                {
                    _posts[0].customize_last_login = UtilityBLL.CustomizeDate((DateTime)_posts[0].last_login, DateTime.Now);
                }
                return(Ok(new { status = "ok", post = _posts[0] }));
            }
        }