Esempio n. 1
0
        public static string AuthorizeUser(string user_name = "", string password = "")
        {
            string result = "Unknown user name or password.";

            try
            {
                IParameterCollection Params = new ParameterCollection();
                Params.Add("@login", user_name);
                Params.Add("@password", password);
                SqlManager M           = new DersaAnonimousSqlManager();
                int        checkresult = M.ExecuteSPWithResult("DERSA_USER$CanAuthorize", false, Params);
                if (checkresult == (int)DersaUserStatus.active)
                {
                    IAuthenticationManager authenticationManager = HttpContext.Current.GetOwinContext().Authentication;
                    authenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
                    var User = new UserProvider(user_name);
                    System.Security.Claims.ClaimsIdentity identity = new System.Security.Claims.ClaimsIdentity(User.Identity, null, "ApplicationCookie", null, null);
                    authenticationManager.SignIn(new AuthenticationProperties()
                    {
                        IsPersistent = false
                    }, identity);
                    return("");
                }
                switch (checkresult)
                {
                case (int)DersaUserStatus.registered:
                    result = "Your registration is not completed.";
                    break;
                }
            }
            catch { throw; }
            return(result);
        }
Esempio n. 2
0
        public string Register(string login, string password, string name, string email)
        {
            if (string.IsNullOrEmpty(login))
            {
                return("Не заполнено имя пользователя");
            }
            IParameterCollection Params = new ParameterCollection();

            Params.Add("@login", login);
            SqlManager M           = new DersaAnonimousSqlManager();
            int        checkresult = M.ExecuteSPWithResult("DERSA_USER$Exists", false, Params);

            if (checkresult > 0)
            {
                return("Пользователь с таким логином уже зарегистрирован");
            }
            Params.Add("@email", Cryptor.Encrypt(email, Util.GetDefaultPassword()));
            checkresult = M.ExecuteSPWithResult("DERSA_USER$Exists", false, Params);
            if (checkresult > 0)
            {
                return("Пользователь с таким email уже зарегистрирован");
            }
            try
            {
                Token(login, email);
                System.Data.DataTable T = M.ExecuteSPWithParams("DERSA_USER$Register", new object[] { login, password, Cryptor.Encrypt(email, Util.GetDefaultPassword()), name });
                return("");
            }
            catch (Exception exc)
            {
                return(exc.Message);
            }
        }
Esempio n. 3
0
        public string Activate(string token)
        {
            string               sresult = Cryptor.Decrypt(token, Util.GetDefaultPassword());
            ActivateStruct       S       = JsonConvert.DeserializeObject(sresult, typeof(ActivateStruct)) as ActivateStruct;
            IParameterCollection Params  = new ParameterCollection();

            Params.Add("@id", S.userid);
            Params.Add("@login", S.username);
            Params.Add("@password", Util.GetPassword(S.username));
            SqlManager M = new DersaAnonimousSqlManager();

            int checkresult = M.ExecuteSPWithResult("DERSA_USER$Activate", false, Params);

            return(S.username);
        }
Esempio n. 4
0
        public void DownloadReport(int id, string parameters)
        {
            DersaSqlManager      M      = new DersaAnonimousSqlManager();
            IParameterCollection Params = Util.DeserializeParams(parameters);

            if (Params.Contains("proc_name"))
            {
                StreamWriter SW        = null;
                string       proc_name = Params["proc_name"].Value.ToString();
                Params.Remove("proc_name");
                try
                {
                    Response.ContentType = "application/force-download; charset =windows-1251";
                    string Header = "Filename=" + "report_" + id.ToString() + ".csv";  //Attachment;
                    Response.AppendHeader("Content-Disposition", Header);

                    //MemoryStream S = new MemoryStream();
                    //SW = new StreamWriter(S);
                    SW = new StreamWriter(Response.OutputStream, System.Text.Encoding.Default);
                    M.ExecSqlToStream(proc_name, SW, Params);
                    SW.Close();
                    //string result = System.Text.Encoding.UTF8.GetString(S.ToArray());
                    //byte[] btres = System.Text.Encoding.Default.GetBytes(result);
                    //Response.AppendHeader("Content-Length", btres.Length.ToString());
                    //Response.OutputStream.Write(btres, 0, btres.Length);
                    Response.End();
                }
                catch (Exception exc)
                {
                    Response.OutputStream.Flush();
                    Response.OutputStream.Close();
                    Response.ContentType = "TEXT/HTML";
                    Response.ClearHeaders();
                    Response.Write(exc.Message);
                }
            }
            else
            {
                throw new System.Exception("procedure for report is not defined!");
            }
        }
Esempio n. 5
0
        public string Token(string login, string email = "")
        {
            ActivateStruct S      = new ActivateStruct(login, 1);
            string         JS     = JsonConvert.SerializeObject(S);
            string         result = Cryptor.Encrypt(JS, Util.GetDefaultPassword());
            string         token  = System.Web.HttpUtility.UrlEncode(result);
            SmtpClient     Smtp   = new SmtpClient("robots.1gb.ru", 25);

            Smtp.Credentials = new NetworkCredential("u483752", "5b218ad92ui");
            MailMessage Message = new MailMessage();

            Message.From = new MailAddress("*****@*****.**");
            DersaAnonimousSqlManager DM = new DersaAnonimousSqlManager();

            System.Data.DataTable T = DM.ExecuteSPWithParams("DERSA_USER$GetInfo", new object[] { login });
            if (email == "")
            {
                if (T.Rows.Count > 0)
                {
                    email = Cryptor.Decrypt(T.Rows[0]["email"].ToString(), Util.GetDefaultPassword());
                }
            }
            if (email == "")
            {
                return("Undefined email");
            }
            Message.To.Add(new MailAddress(email));
            Message.Subject = "регистрация в проекте DERSA";
            Message.Body    = string.Format("Вы успешно зарегистрировались в проекте DERSA. Для активации вашего аккаунта пройдите по ссылке: http://{0}/account/activate?token={1}", HttpContext.Current.Request.Url.Authority, token);

            try
            {
                Smtp.Send(Message);
                return("Success! Letter sent to " + email + "(robots.1gb.ru, 25) ; token = [" + token + "]");
            }
            catch (SmtpException exc)
            {
                return(exc.Message);
            }
            return("Unknown error");
        }
 public string GetAttrValue(string attrName, string entityId, string userName = null)
 {
     try
     {
         DersaSqlManager DM = new DersaAnonimousSqlManager();
         if (userName == null)
         {
             userName = "******";
         }
         return(Util.GetAttributeValue(userName, int.Parse(entityId), attrName, -1));
         //System.Data.DataTable T = DM.ExecuteSPWithParams("ENTITY$GetAttribute", new object[] { entityId, attrName, userName, Util.GetPassword(userName) });
         //string result = "";
         //if (T.Rows.Count > 0)
         //    result = T.Rows[0]["Value"].ToString();
         //return result;
     }
     catch (Exception exc)
     {
         return("");
     }
 }