protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            Account_Information myaaccinfo = new Account_Information();
            txt_EMPGuid.Text = myaaccinfo.ReturnGuidFrom_AD(HttpContext.Current.User.Identity.Name.ToString());
            try
            {
                txt_EMPID.Text = myaaccinfo.Return_EmpID(txt_EMPGuid.Text);
                txt_EMPRoleID.Text = myaaccinfo.Return_EmpRoleid(txt_EMPGuid.Text);
            }
            catch
            {
                Response.Redirect("access_denied.aspx");
            }

            myaaccinfo.Dispose();

            Site_EventLoggin obj_logevent = new Site_EventLoggin();
            obj_logevent.writeLogg(txt_EMPID.Text + " with Guid " + txt_EMPGuid.Text + " has hit the master page at time: " + System.DateTime.Now.ToString());
            obj_logevent.Dispose();

            /* Check if user is enabled */

            SqlConnection myconn = new SqlConnection(WebConfigurationManager.ConnectionStrings["sctcs_Grants"].ConnectionString);
            SqlCommand mycomm = new SqlCommand("pr_scs_college_user_status_get", myconn);
            mycomm.CommandType = CommandType.StoredProcedure;
            mycomm.Parameters.AddWithValue("@key_user_id", txt_EMPID.Text);

            if (myconn.State == ConnectionState.Closed)
                myconn.Open();

            SqlDataReader dr = mycomm.ExecuteReader();

            if (dr.HasRows)
                while (dr.Read())
                {
                    if (((bool)dr["flg_enabled"]) == false)
                        Response.Redirect(WebConfigurationManager.AppSettings.Get("AppLocation").ToString() + "/ErrorHandler.aspx?err=104");
                }

            mycomm.Dispose();
            myconn.Dispose();
        }
    }
示例#2
0
        public static UserModel MapUserModel(Account account, bool deepLoad, bool loadUserInformation = false)
        {
            if (account != null)
            {
                UserModel userModel = new UserModel()
                {
                    Id        = account.ID,
                    FirstName = account.FirstName,
                    LastName  = account.LastName,
                    Username  = account.UserName,
                    Image     = account.Image,
                    ClubId    = account.ClubId,
                    Gender    = (Gender)account.Gender
                };

                userModel.Club = new ClubModel()
                {
                    Id        = account.ClubId,
                    Name      = account.Club.Name,
                    ShortName = account.Club.ShortName,
                    Image     = account.Club.Image
                };

                if (deepLoad)
                {
                    Parallel.Invoke(() =>
                    {
                        userModel.Token = AccountBLL.GetUserSession(account.ID);
                    }, () =>
                    {
                        foreach (var item in account.AccountAccess)
                        {
                            foreach (var right in item.Accessright.Accessright_Right)
                            {
                                userModel.AccessRightsRight.Add(new AccessrightRightModel()
                                {
                                    AccessType      = (AccessType)right.AccessType,
                                    AccessTypeRight = (AccessTypeRight)right.AccessTypeRight,
                                    Id = right.Id
                                });
                            }
                        }
                    }, () =>
                    {
                        foreach (var item in account.AccountAccess)
                        {
                            userModel.AccessRights.Add(new AccessrightModel()
                            {
                                Id          = item.Accessright.ID,
                                Name        = item.Accessright.Name,
                                Description = item.Accessright.Description
                            });
                        }
                    }, () =>
                    {
                        Account_Information information = AccountBLL.GetAccountSettings(userModel.Id);
                        if (information != null)
                        {
                            userModel.UserInformation = new UserInformationModel()
                            {
                                Email      = information.Email,
                                City       = information.City,
                                Occupation = information.Occupation,
                                Phone      = information.Phone,
                                Street     = information.Street,
                                Zip        = information.Zip,
                                Birthday   = information.Birthday,
                                Grade      = (SW.Core.Enums.Grade)information.Grade,
                                Weight     = information.Weight,
                                Theme      = information.Theme
                            };
                        }
                    }, () =>
                    {
                        userModel.AccountAccess = AccountAccessModel.MapAccountAccesses(AccountBLL.GetAccountAccesses(userModel.Id));
                    }, () =>
                    {
                        userModel.GenericValues = AccountInformationGeneric.MapValues(
                            AccountBLL.GetGenericValues(userModel.Id, userModel.ClubId));
                    });
                }
                else if (loadUserInformation)
                {
                    Account_Information information = AccountBLL.GetAccountSettings(userModel.Id);
                    if (information != null)
                    {
                        userModel.UserInformation = new UserInformationModel()
                        {
                            Email      = information.Email,
                            City       = information.City,
                            Occupation = information.Occupation,
                            Phone      = information.Phone,
                            Street     = information.Street,
                            Zip        = information.Zip,
                            Birthday   = information.Birthday,
                            Grade      = (SW.Core.Enums.Grade)information.Grade,
                            Weight     = information.Weight,
                            Theme      = information.Theme
                        };
                    }
                }

                return(userModel);
            }

            return(new UserModel()
            {
                GenericValues = AccountInformationGeneric.MapValues(
                    AccountBLL.GetGenericValues(0, 0))
            });
        }
示例#3
0
        public static void ImportUsersFromExcel(byte[] data, int clubId, bool sendWelcomeMail,
                                                bool tryToMatchGroupName, List <int> accessrightIds)
        {
            MemoryStream ms = new MemoryStream(data);
            DataTable    dt = ExcelHelper.GetDataTableFromXls(ms);

            foreach (DataRow row in dt.Rows)
            {
                Account acc = new Account();
                try
                {
                    string password = GenerateRandomPassword(5);
                    acc = new Account()
                    {
                        ClubId    = clubId,
                        FirstName = row["Förnamn"].ToString(),
                        Gender    = row["Kön"].ToString().ToLower() == "man" ? 0 : 1,
                        LastName  = row["Efternamn"].ToString(),
                        UserName  = row["E-post 1"].ToString(),
                        Password  = password,
                        Image     = string.Empty
                    };

                    Account_Information info = new Account_Information()
                    {
                        AccountId  = acc.ID,
                        City       = row["Ort"].ToString(),
                        Email      = row["E-post 1"].ToString(),
                        Phone      = row["Mobiltelefon"].ToString(),
                        Street     = row["Adress"].ToString(),
                        Zip        = row["Postnummer"].ToString(),
                        Grade      = 16,
                        Birthday   = DateTime.Now,
                        Occupation = "-",
                        Weight     = "-",
                        Theme      = "blue"
                    };

                    acc.Account_Information.Add(info);

                    if (tryToMatchGroupName)
                    {
                        TryToMatchGroupName(acc, row["Gruppkoppling"].ToString(), clubId);
                    }
                    else
                    {
                        foreach (int accessrightId in accessrightIds)
                        {
                            DAL.AccountAccess accAccess = new AccountAccess()
                            {
                                AccessID  = accessrightId,
                                AccountID = acc.ID
                            };

                            acc.AccountAccess.Add(accAccess);
                        }
                    }

                    SaveAccount(acc);

                    if (sendWelcomeMail)
                    {
                        SendWelcomeMail(acc, password);
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.LogError(string.Format("Error importing user: {0} {1} - username: {2}",
                                                     acc.FirstName, acc.LastName, acc.UserName), ex, clubId);
                }
            }
        }