public User Registration(string username, string password, string Ime, string Priimek, string number, string mail) { User ret = new RESTService.User { ID = -1, Username = username, Ime = Ime, Priimek = Priimek, Telefon = number, Mail = mail }; SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["LoftApp2ConnectionString"].ConnectionString); conn.Open(); string sql = "INSERT INTO \"User\" (Name,Surname, Phonenumber,Mail, Password, Username) VALUES (@Ime, @Priimek, @number, @Mail, @Geslo, @Username)"; string sql2 = "Select ID from \"User\" where Username = @username"; SqlCommand comm = new SqlCommand(sql, conn); /*try * {*/ if (checkUsername(username) && checkMail(mail)) { comm.Parameters.AddWithValue("@Username", username); comm.Parameters.AddWithValue("@Ime", Ime); comm.Parameters.AddWithValue("@Priimek", Priimek); comm.Parameters.AddWithValue("@Geslo", MD5Hash(password)); comm.Parameters.AddWithValue("@Mail", mail); comm.Parameters.AddWithValue("@number", number); comm.ExecuteNonQuery(); SqlCommand comma = new SqlCommand(sql2, conn); comma.Parameters.AddWithValue("@username", username); using (var reader = comma.ExecuteReader()) if (reader.Read()) { ret.ID = reader.GetInt32(0); } else { return(ret); } conn.Close(); return(ret); } else { return(ret); } /*} * catch (Exception) * { * return ret; * }*/ }
public List <User> GetUsersFromSL(string IDs) { List <User> ret = new List <User>(); string sql = "Select ID from ShoppingList_Users where Sho_ID = @ids"; string sql2 = "Select Name, Surname , Phonenumber, Mail, Username from \"User\" where ID = @id"; SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["LoftApp2ConnectionString"].ConnectionString); SqlConnection connx = new SqlConnection(ConfigurationManager.ConnectionStrings["LoftApp2ConnectionString"].ConnectionString); conn.Open(); connx.Open(); SqlCommand comm = new SqlCommand(sql, conn); comm.Parameters.AddWithValue("@ids", IDs); using (var reader = comm.ExecuteReader()) { while (reader.Read()) { User nou = new RESTService.User { ID = reader.GetInt32(0) }; SqlCommand comma = new SqlCommand(sql2, connx); comma.Parameters.AddWithValue("@id", nou.ID); using (var reader1 = comma.ExecuteReader()) { while (reader1.Read()) { nou.Ime = reader1.GetString(0); nou.Priimek = reader1.GetString(1); nou.Telefon = reader1.GetString(2); nou.Mail = reader1.GetString(3); nou.Username = reader1.GetString(4); } } ret.Add(nou); } } return(ret); }
public User Login(string username, string password) { string cookie = Authenticate(username, password); User ret = new RESTService.User { ID = -1 }; if (cookie != null) { SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["LoftApp2ConnectionString"].ConnectionString); conn.Open(); string sql = "select ID from \"User\" where Username = @username"; SqlCommand comm = new SqlCommand(sql, conn); comm.Parameters.AddWithValue("@username", username); try { using (var command = comm) { using (var reader = command.ExecuteReader()) { while (reader.Read()) { ret.ID = reader.GetInt32(0); } } } return(ret); } catch (Exception) { return(ret); } } else { return(ret); } }